2

I wrote swap on assembly, but I'm not sure that my code is right, this is the code

swap:  mov r1, -(sp)   

   mov (sp) r1
   mov 2(sp) (sp)
   mov r1 2(sp)

   mov (sp)+, r1
   rts pc

swap receives pointer from stack

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
lego69
  • 767
  • 1
  • 12
  • 20

1 Answers1

1

is sp a stackpointer? There is usually the command ldw rA, 0(rB) (0 is the offset and rB is the address you will load from, the actual data is now in rA). ldw loads a whole word into the memory, ldb loads a byte, stw rA, 0(rB) stores a word. mov usually copies one register to another.

Joelmob
  • 1,076
  • 2
  • 10
  • 22