Normally, the SPIM simulator itself allocates an address to the instructions in a program. Is there some way to manually choose where to store a particular instruction?
Asked
Active
Viewed 434 times
-1
-
show us what you have – lomse Feb 19 '19 at 19:00
1 Answers
0
Sure, the .text
directive has an optional argument where you can specify an address:
.text
.globl main
# This code ends up at the default address for the .text section
main:
li $a0,1
jal foo
li $v0,1
syscall
li $v0,10
syscall
.text 0x430000
# This code ends up at address 0x430000
foo:
li $a0,2
jr $ra
Of course you can't just pick an address at random. It must be valid for the target environment (QtSpim in my example).
Another possibility is to assemble everything into the default location, and then copy parts of the code into RAM at runtime and execute it from there.

Michael
- 57,169
- 9
- 80
- 125
-
What if I want to store a single instruction set out of let’s say 10 at a particular location. What exactly I need to do is somehow go to a label outside the 16 bit range of beq. – Mohit Aggarwal Feb 19 '19 at 18:08