-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
539 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# test for error handling of duplicate symbol | ||
Begin: | ||
halt | ||
Begin: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.