0
mov 8[+r1], 1337

Edit, after having read the recommended thread of dwelch I get to (assuming I understood it right):

add #8, r1
mov #1337, r2
mov [r1], [r2]
sub #7, r1

Is this correct or did I do mistakes?

Info we had about the assembler:

  • n[+rx] register indexed with pre-increment; n is index value and rx is register x
  • rx register directly addressing

  • [rx] register indirect addressing

  • #n immediate addressing

We may only use add, sub, mov. Except for r1 we may additionally modify r2 if necessary.

I hope I did it correctly?

rpbudd
  • 77
  • 9
  • Why is `sub #1336, r2` needed? – Sep Roland Jul 03 '16 at 17:04
  • It's / should be needed for the increment +1. You substract it from 1337 and get +1 increment (increment needed because of the [+r1]). – rpbudd Jul 03 '16 at 17:08
  • Since `r1` uses the pre-increment, what would be the use of doing it for `r2` ? – Sep Roland Jul 03 '16 at 17:12
  • But how would you do the increment thing then? – rpbudd Jul 03 '16 at 17:13
  • 1
    Wouldn't this easily be answered by simply executing the code? If you mean "did I decompose this more complex instruction into a set of simpler instructions with the exact same outcome" then you would basically just examine the registers and memory locations involved before and after each solution, then you would easily see if the end result is the same. Considering that you're trampling the r2 register, that's at least one difference. – Lasse V. Karlsen Jul 03 '16 at 17:19
  • Lasse I'm really not sure how I would execute that. I'm very new in this and I haven't got any programs / never learned how to use them. Only did this on paper so far and I'm very noob (1 week). – rpbudd Jul 03 '16 at 17:21
  • 1
    we just had this homework question the other day, why not read that one? if you understand one you understand the other. – old_timer Jul 03 '16 at 18:11
  • @dwelch : See my edit please, is it correct now? I really don't want use another solution where other things have been modified. – rpbudd Jul 03 '16 at 20:49
  • 1
    this is an asked and answered question, you want to know how to do it or if you have the shortest solution it was already asked and answered. What is the point of everyone in the class asking the same question? This is not a homework service. – old_timer Jul 03 '16 at 21:15

1 Answers1

1
add #8, r1
mov #1337, r2
mov [r1], [r2]

This doesn't seem to incorporate the pre-increment on the r1 register.
Just add 9 instead of 8.

add #9, r1
mov #1337, r2
mov [r1], [r2]
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • I think problem is the limit in the task: "Except for r1 we may additionally modify r2 if necessary." So it wouldn't be allowed for me to change #8 to #9 or am I wrong? Tyvm for your help btw! – rpbudd Jul 03 '16 at 17:19
  • Since you stated "*I* changed to", we all think that *you* wrote the 4 lines of code. Then obviously you are free to write any numbers you like to solve the task. – Sep Roland Jul 03 '16 at 17:26