0

Hi I'm writing a lc3 subroutine to compute the square of a value in n and then place that value in r0, i have wrote the code and it seems to be filling r0 with the sumofsums however at the end of the program the value in r0 ends up being x7fff - i'm not sure whats changing the value any ideas? my code is below

.orig x3FF8
 ld r1,n
ld r5,n
and r0,r0,#0
 square


add r0, r0,r1 ; add sum to r0

add r5,r5,#-1 ;decrement counter(amount of times to add sum)

brp square ;loop


theend



n .fill #4

.end
rahulchawla
  • 170
  • 1
  • 3
  • 20
  • In comments on the OP's previous question, [they said](https://stackoverflow.com/questions/47765417/lc3-assembly-square-of-n#comment82492877_47765521) there was a `LD R0, xFD7D` instruction changing `R0` after their code. – Peter Cordes Dec 13 '17 at 03:39
  • You seem to have left out the `halt` after the loop. Won't execution continue into `.fill #4` and decode `n` as an instruction? Is that the "load" instruction? – Peter Cordes Dec 13 '17 at 03:40
  • @PeterCordes I tried adding halt - no difference. – rahulchawla Dec 13 '17 at 14:46
  • .fill is assigning 1 space in memory @PeterCordes – rahulchawla Dec 13 '17 at 14:47
  • Yes, exactly. What instruction does the byte `4` represent in LC-3 machine code? Instructions are also just bytes in memory. But if HALT didn't make a difference, then that's probably not the problem. – Peter Cordes Dec 13 '17 at 14:49
  • mhm so what can I do to approach this issue..? @PeterCordes seeing as taking the n.fill out is not an option as I need it for the program – rahulchawla Dec 13 '17 at 15:03
  • Wait for someone else to answer this question, if you can't solve it yourself by learning more about how LC-3 works, or about the simulator you're using. – Peter Cordes Dec 13 '17 at 15:05
  • 1
    What LC3 simulator is being used? I see no reason (aside from the lack of HALT statement) that this code would not work correctly. – Brandon Dec 15 '17 at 06:31

0 Answers0