0
pointr: .word pointr
mov #pointr,r0
mov pointr,r1

Can someone please explain the difference between the values r0 and r1?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Sam12
  • 1,805
  • 2
  • 15
  • 23
  • 1
    From experience with asm syntax for other machines, likely `#pointr` is an immediate operand (the address of the label), while `pointr` is a memory source operand, so the 2nd `mov` is a load instruction. – Peter Cordes Jul 01 '18 at 02:42
  • 2
    `pointr: .word pointr` creates a label for a word value containing the actual absolute address of `pointr`. `mov #pointr,r0` uses immediate mode to move the value of the `pointr` label directly to r0. `mov pointr,r1` uses relative mode to move the word value at `pointr` into `r1`. Since the word value stored at `pointr` is the address of `pointr` itself it has the effect of moving the address of `pointr` to r1. The values in r0 and r1 should be the same. – Michael Petch Jul 01 '18 at 19:45
  • what assembler are you using, syntax is determined by assembler, and with the port of pdp-11 to gnu the gnu assembler syntax is very much not compatible with DEC pdp-11 assembler (documentation). I assume this is gnu assembler? – old_timer Jul 24 '18 at 13:55

1 Answers1

1

TL;DR - r0 and r1 will hold the same value, but just because of the initialization in the first line

Let's break this down, instruction by instruction:

pointr: .word pointr

This means "define a label named 'pointer' in address X, and put the value of the label (in this case, X) in that address". So in address X there's a word holding the value X.

mov #pointr,r0

This means "move the value of label 'pointr' (in this case, the address X) to r0". So r0 will hold the value X because 'pointr' is the label for this address.

mov pointr,r1

This means "move the value that sits in the address of label 'pointr' (in this case, also X) to r1". So r1 will hold the value X because of the ".word pointr" part of the first line in code.

To clarify, if we were to replace the first line of code to get:

pointr: .word pointr+2 mov #pointr,r0 mov pointr,r1

the value of r0 will not change (in comparison to the original code), but the value of r1 will.

Orr Goldman
  • 35
  • 1
  • 7