Skip to content

Commit

Permalink
add data, prepare for y86asm
Browse files Browse the repository at this point in the history
  • Loading branch information
hczhcz committed May 23, 2014
1 parent a8db7e3 commit 9aeb695
Show file tree
Hide file tree
Showing 61 changed files with 539 additions and 2 deletions.
52 changes: 52 additions & 0 deletions y86-app/abs-asum-cmov.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Modification of asum code to compute absolute values of entries.
# This version uses a conditional jump
# Execution begins at address 0
.pos 0
init: irmovl Stack, %esp # Set up Stack pointer
irmovl Stack, %ebp # Set up base pointer
jmp Main # Execute main program

# Array of 4 elements
.align 4
array: .long 0x0000000d
.long 0xffffff40 # -0xc0
.long 0x00000b00
.long 0xffff6000 # -0xa0000

Main: irmovl $4,%eax
pushl %eax # Push 4
irmovl array,%edx
pushl %edx # Push array
call AbsSum # Sum(array, 4)
halt

# int AbsSum(int *Start, int Count)
AbsSum:
pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ecx # ecx = Start
mrmovl 12(%ebp),%edx # edx = Count
irmovl $0, %eax # sum = 0
andl %edx,%edx
je End
#/* $begin abs-sum-cmov-ys 0 */
Loop:
mrmovl (%ecx),%esi # get x = *Start
irmovl $0,%edi # 0
subl %esi,%edi # -x
cmovg %edi,%esi # if -x > 0 then x = -x
addl %esi,%eax # add x to sum
irmovl $4,%ebx #
addl %ebx,%ecx # Start++
irmovl $-1,%ebx #
addl %ebx,%edx # Count--
jne Loop # Stop when 0
#/* $end abs-sum-cmov-ys 0 */
End:
popl %ebp
ret

.pos 0x100
Stack: # The stack goes here
#/* $end code-ysa */
#/* $end code-yso */
53 changes: 53 additions & 0 deletions y86-app/abs-asum-jmp.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Modification of asum code to compute absolute values of entries.
# This version uses a conditional jump
# Execution begins at address 0
.pos 0
init: irmovl Stack, %esp # Set up Stack pointer
irmovl Stack, %ebp # Set up base pointer
jmp Main # Execute main program

# Array of 4 elements
.align 4
array: .long 0x0000000d
.long 0xffffff40 # -0xc0
.long 0x00000b00
.long 0xffff6000 # -0xa0000

Main: irmovl $4,%eax
pushl %eax # Push 4
irmovl array,%edx
pushl %edx # Push array
call AbsSum # Sum(array, 4)
halt

#/* $begin abs-sum-jmp-ys 0 */
# int AbsSum(int *Start, int Count)
AbsSum:
pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ecx # ecx = Start
mrmovl 12(%ebp),%edx # edx = Count
irmovl $0, %eax # sum = 0
andl %edx,%edx
je End
Loop:
mrmovl (%ecx),%esi # get x = *Start
irmovl $0,%edi # 0
subl %esi,%edi # -x
jle Pos # Skip if -x <= 0
rrmovl %edi,%esi # x = -x
Pos:
addl %esi,%eax # add x to sum
irmovl $4,%ebx #
addl %ebx,%ecx # Start++
irmovl $-1,%ebx #
addl %ebx,%edx # Count--
jne Loop # Stop when 0
End:
popl %ebp
ret
#/* $end abs-sum-jmp-ys 0 */
.pos 0x100
Stack: # The stack goes here
#/* $end code-ysa */
#/* $end code-yso */
53 changes: 53 additions & 0 deletions y86-app/asum.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#/* $begin code-yso */
#/* $begin code-ysa */
# Execution begins at address 0
.pos 0
init: irmovl Stack, %esp # Set up stack pointer
irmovl Stack, %ebp # Set up base pointer
call Main # Execute main program
halt # Terminate program

# Array of 4 elements
.align 4
array: .long 0xd
.long 0xc0
.long 0xb00
.long 0xa000

Main: pushl %ebp
rrmovl %esp,%ebp
irmovl $4,%eax
pushl %eax # Push 4
irmovl array,%edx
pushl %edx # Push array
call Sum # Sum(array, 4)
rrmovl %ebp,%esp
popl %ebp
ret

#/* $begin sum-ys 0 */
# int Sum(int *Start, int Count)
Sum: pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ecx # ecx = Start
mrmovl 12(%ebp),%edx # edx = Count
xorl %eax,%eax # sum = 0
andl %edx,%edx # Set condition codes
je End
Loop: mrmovl (%ecx),%esi # get *Start
addl %esi,%eax # add to sum
irmovl $4,%ebx #
addl %ebx,%ecx # Start++
irmovl $-1,%ebx #
addl %ebx,%edx # Count--
jne Loop # Stop when 0
End: rrmovl %ebp,%esp
popl %ebp
ret
#/* $end sum-ys 0 */

# The stack starts here and grows to lower addresses
.pos 0x100
Stack:
#/* $end code-ysa */
#/* $end code-yso */
48 changes: 48 additions & 0 deletions y86-app/asumr.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Execution begins at address 0
.pos 0
init: irmovl Stack, %esp # Set up Stack pointer
irmovl Stack, %ebp # Set up base pointer
jmp Main # Execute main program

# Array of 4 elements
.align 4
array: .long 0xd
.long 0xc0
.long 0xb00
.long 0xa000

Main: irmovl $4,%eax
pushl %eax # Push 4
irmovl array,%edx
pushl %edx # Push array
call rSum # Sum(array, 4)
halt

#/* $begin rsum-ys */
# int Sum(int *Start, int Count)
rSum: pushl %ebp
rrmovl %esp,%ebp
pushl %ebx # Save value of %ebx
mrmovl 8(%ebp),%ebx # Get Start
mrmovl 12(%ebp),%eax # Get Count
andl %eax,%eax # Test value of Count
jle L38 # If <= 0, goto zreturn
irmovl $-1,%edx
addl %edx,%eax # Count--
pushl %eax # Push Count
irmovl $4,%edx
rrmovl %ebx,%eax
addl %edx,%eax
pushl %eax # Push Start+1
call rSum # Sum(Start+1, Count-1)
mrmovl (%ebx),%edx
addl %edx,%eax # Add *Start
jmp L39 # goto done
L38: xorl %eax,%eax # zreturn:
L39: mrmovl -4(%ebp),%ebx # done: Restore %ebx
rrmovl %ebp,%esp # Deallocate stack frame
popl %ebp # Restore %ebp
ret
#/* $end rsum-ys */
.pos 0x400
Stack: # The stack goes here
17 changes: 17 additions & 0 deletions y86-app/cjr.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# /* $begin cjr-ys */
# Code to generate a combination of not-taken branch and ret
irmovl Stack, %esp
irmovl rtnp,%eax
pushl %eax # Set up return pointer
xorl %eax,%eax # Set Z condition code
jne target # Not taken (First part of combination)
irmovl $1,%eax # Should execute this
halt
target: ret # Second part of combination
irmovl $2,%ebx # Should not execute this
halt
rtnp: irmovl $3,%edx # Should not execute this
halt
.pos 0x40
Stack:
# /* $end cjr-ys */
15 changes: 15 additions & 0 deletions y86-app/j-cc.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
irmovl $1, %esi
irmovl $2, %edi
irmovl $4, %ebp
irmovl $-32, %eax
irmovl $64, %edx
subl %edx,%eax
je target
nop
halt
target:
addl %esi,%edx
nop
nop
nop
halt
6 changes: 6 additions & 0 deletions y86-app/poptest.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test of Pop semantics for Y86
irmovl $0x100,%esp # Initialize stack pointer
irmovl $0xABCD,%eax
pushl %eax # Put known value on stack
popl %esp # Either get 0xABCD, or 0xfc
halt
8 changes: 8 additions & 0 deletions y86-app/prog1.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# prog1: Pad with 3 nop's
irmovl $10,%edx
irmovl $3,%eax
nop
nop
nop
addl %edx,%eax
halt
7 changes: 7 additions & 0 deletions y86-app/prog10.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# prog10
irmovl $1,%eax
xorl %esp,%esp # Set stack pointer to 0 and CC to 100
pushl %eax # Attempt to write to 0xfffffffc
addl %eax,%eax # (Should not be executed) Would set CC to 000
irmovl $2, %eax # Not executed
irmovl $3, %eax # Not executed
7 changes: 7 additions & 0 deletions y86-app/prog2.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# prog2: Pad with 2 nop's
irmovl $10,%edx
irmovl $3,%eax
nop
nop
addl %edx,%eax
halt
6 changes: 6 additions & 0 deletions y86-app/prog3.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# prog3: Pad with 1 nop
irmovl $10,%edx
irmovl $3,%eax
nop
addl %edx,%eax
halt
5 changes: 5 additions & 0 deletions y86-app/prog4.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# prog4: No padding
irmovl $10,%edx
irmovl $3,%eax
addl %edx,%eax
halt
8 changes: 8 additions & 0 deletions y86-app/prog5.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# prog5: Load/use hazard
irmovl $128,%edx
irmovl $3,%ecx
rmmovl %ecx, 0(%edx)
irmovl $10,%ebx
mrmovl 0(%edx), %eax # Load %eax
addl %ebx,%eax # Use %eax
halt
5 changes: 5 additions & 0 deletions y86-app/prog6.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# prog6: Forwarding Priority
irmovl $10,%edx
irmovl $3,%edx
rrmovl %edx,%eax
halt
14 changes: 14 additions & 0 deletions y86-app/prog7.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Demonstration of return
# /* $begin prog7-ys */
# prog7
irmovl Stack,%esp # Initialize stack pointer
call Proc # procedure call
irmovl $10,%edx # return point
halt
.pos 0x20
Proc: # Proc:
ret # return immediately
rrmovl %edx,%ebx # not executed
.pos 0x30
Stack: # Stack: Stack pointer
# /* $end prog7-ys */
13 changes: 13 additions & 0 deletions y86-app/prog8.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Demonstrate branch cancellation
# /* $begin prog8-ys */
# prog8
xorl %eax,%eax
jne target # Not taken
irmovl $1, %eax # Fall through
halt
target:
irmovl $2, %edx # Target
irmovl $3, %ebx # Target+1
# /* $end prog8-ys */
halt

9 changes: 9 additions & 0 deletions y86-app/prog9.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Exception handling
# /* $begin prog9-yo */
xorl %eax,%eax
jne Target # Not taken
irmovl $1, %eax # Fall through
halt
Target:
.byte 0xFF # Invalid instruction code
# /* $end prog9-yo */
5 changes: 5 additions & 0 deletions y86-app/pushquestion.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Assembly Code to test semantics of pushl
irmovl $0x100, %esp
pushl %esp # Ambiguous
popl %eax
halt
7 changes: 7 additions & 0 deletions y86-app/pushtest.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test of Push semantics for Y86
irmovl $0x100,%esp # Initialize stack pointer
rrmovl %esp,%eax # Save stack pointer
pushl %esp # Push the stack pointer (old or new?)
popl %edx # Get it back
subl %edx,%eax # Compute difference. Either 0 (old) or 4 (new).
halt
13 changes: 13 additions & 0 deletions y86-app/ret-hazard.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#/* $begin ret-hazard-ys */
# Test instruction that modifies %esp followed by ret
irmovl mem,%ebx
mrmovl 0(%ebx),%esp # Sets %esp to point to return point
ret # Returns to return point
halt #
rtnpt: irmovl $5,%esi # Return point
halt
.pos 0x40
mem: .long stack # Holds desired stack pointer
.pos 0x50
stack: .long rtnpt # Top of stack: Holds return point
#/* $end ret-hazard-ys */
4 changes: 4 additions & 0 deletions y86-err/delim-missing-error.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# test for error-handling for missing delimiter
rrmovl %esp %ebp
halt
# end
4 changes: 4 additions & 0 deletions y86-err/dup-symbol-error.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# test for error handling of duplicate symbol
Begin:
halt
Begin:
4 changes: 4 additions & 0 deletions y86-err/invalid-dest-error.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# test for error handling of invalid dest for JXX/CALL
jmp 123
halt
# end
4 changes: 4 additions & 0 deletions y86-err/invalid-directive-error.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# test for error handling of invalid directive
.long xyz
halt
# end
4 changes: 4 additions & 0 deletions y86-err/invalid-imm-error.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# test for error handling of invalid immediate
irmovl $abc, %ebx
halt
# end
Loading

0 comments on commit 9aeb695

Please sign in to comment.