0
.text
.globl main
 main: 


ori         $v0,4           #code 4 == print string
lui         $a0,0x1001      #$a0 == address of the string
syscall

ori         $v0, 10         #code 10 = exit the program
syscall 

.data
 string:     .asciiz         "Enter your number: "
 string2:    .asciiz         "wrong number! "

In the above code, I am able to get the memory address of "string" which is "Enter your number: ". Is there any way I can get the memory address of "string2" without using pseudo instruction such as la. I am using Qtspim to run the code. Thank you guys!

1 Answers1

0

Yes, use ori with the low 16 bits, ie. ori $a0, $a0, 19 (if I counted correctly) or use whatever helper function your assembler has for accessing the low 16 bits, such as %lo(string2).

Jester
  • 56,577
  • 4
  • 81
  • 125
  • is there a better way to figure out the address without counting or looking into the data segment. You dont want to count if the first string is long. – user3517254 Feb 08 '15 at 18:33
  • As I said, if your assembler supports a special function, then yes. Otherwise, you might also try subtracting, ie. `string2-string` or `string2-.data`. – Jester Feb 08 '15 at 18:41