0
votes

I have two questions here :

1)> What is happening in line 2.The 'la' pseudo instruction refers to load address, instead of the literal '3444' there should have been a label.How can it load the address of the literal

2)> if you replace line 3 with "li $a0 3444" which loads 3444 into the register #a0 instead of the address.The output is still the same.What i want to ask from this is that how could syscall know that in #a0 is the address of the variable or the variable itself.How could the subroutine for printing the integer work correctly whether the argument stored in #a0 is the address or the integer value itself.

.text

      li $v0 1 
 >>2  la $a0 3444   # When i replace 3444 literal with the label  'anint' it makes sense and the output of course is the same
      syscall


.data

 anint: .word 3444

Output:

3444

UPDATE#2: I could'nt post the code in a comment so...

IF la(load address) and li(load immediate) both translate to the same instruction i-e loading the literal into #a0 then explain Line 3 from the code segment below.

      .text


      li #v0 4
>>3   la #a0 msg  #This loads the address of the label 'msg in #a0' not the label itself    
      syscall





      .data

       msg: .asciiz "This is a long string that can't be saved in the register!"
1
You shouldn't try to post code in comments anyway. Editing clarifications into your answer is the correct thing to do.Peter Cordes
labels are addresses. They aren't "stored" anywhere themselves, they're just useful ways to write addresses symbolically instead of with numeric addresses.Peter Cordes

1 Answers

2
votes

how could syscall know that in #a0 is the address of the variable or the variable itself

It doesn't. System call 1 in SPIM/MARS always prints the value in $a0.

li $a0,3444 and la $a0,3444 are translated into the same thing (some instruction that loads the value 3334 into register $a0, such as ori $a0, $0, 3334).