forked from TheThirdOne/rars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TheThirdOne#74 from privat/test_selfmod
Test selfmod
- Loading branch information
Showing
5 changed files
with
81 additions
and
4 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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#exit:42 | ||
#selfmod:true | ||
.text | ||
main: | ||
la s0, toload | ||
|
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,59 @@ | ||
#error:Instruction load access error | ||
.text | ||
main: | ||
la s0, toload | ||
la s1, torun | ||
|
||
li a0, 2 | ||
call toload | ||
|
||
# First copy by word to data | ||
lw t0, (s0) | ||
sw t0, (s1) | ||
lw t0, 4(s0) | ||
sw t0, 4(s1) | ||
|
||
# try running it | ||
call torun | ||
|
||
# Copy by byte to data | ||
mv s2, a0 | ||
mv a0, s0 | ||
mv a1, s1 | ||
call copy | ||
|
||
mv a0, s2 | ||
call torun | ||
|
||
# copy to .text | ||
mv s2, a0 | ||
la a0, torun | ||
la a1, main | ||
call copy | ||
|
||
mv a0, s2 | ||
call main | ||
|
||
|
||
li a7, 93 | ||
ecall | ||
|
||
toload: | ||
addi a0, a0, 10 | ||
ret | ||
|
||
copy: | ||
li t0, 0 | ||
li t3, 8 | ||
loop: | ||
add t1, a0, t0 | ||
lb t1, (t1) | ||
add t2, a1, t0 | ||
sb t1, (t2) | ||
addi t0, t0, 1 | ||
blt t0, t3, loop | ||
ret | ||
|
||
.data | ||
torun: | ||
.space 8 |
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 @@ | ||
# Test read-only in the code segment (should not require selfmod to be set) | ||
#stdout:1050771 | ||
.text | ||
foo: li a7, 1 # PrintInt | ||
lw a0, foo | ||
ecall | ||
li a7, 10 | ||
ecall |