Shop OBEX P1 Docs P2 Docs Learn Events
What is "r-field"? — Parallax Forums

What is "r-field"?

I'm trying to understand the concept behind the CALL and JMPRET commands. In the Propeller manual under "RET" is this paragraph: RET is a subset of the JMP instruction but with the i-field set and the s-field unspecified. It is also closely related to the CALL and JMPRET commands; in fact, they are all the same opcode but with different r-field and i-field values and varying assembler-driven and user-driven d-field and s-field values.
I understand 'instruction, 'destination' and 'source' fields but 'r-field' is new to me.
I learned from Mike Green that a repeat loop does not return to the caller. That was a major piece of knowledge when I was learning Spin. For example, if you test the state of a pin, a repeat loop may jump to a second method. Once the second method completes it returns control to the first method and the next instruction in the repeat loop executes.
PASM returns to the next instruction without a call stack. I'd like to grasp the concept at least well enough to test it with the Propeller tool.

Comments

  • By "r-field", they mean the NR bit (and by "i-field" they mean the bit that switches between immediate source (#something) and register source (no #)).

    As it says, CALL,RET and JMP are really just sugar around the JMPRET instruction (which itself is basically just MOVS, except that instead of S being inserted, it's the current PC+1 and it then jumps to S).

    Example:
    
    '' In Spin
    
    PUB main
    
      repeat
        togglepin
    
    PRI togglepin
      outa ^= 1
    
    '' In sane PASM
    
    :loop
           call #togglepin
           jmp #:loop
    
    togglepin
           xor outa,#1
    togglepin_ret
           ret
    
    '' In sane PASM, but without the "sugar" (will assemble to the exact same binary)
    
    :loop
           jmpret togglepin_ret,#togglepin
           jmpret 0,#:loop  nr
    
    togglepin
           xor outa,#1
    togglepin_ret
           jmpret 0,#0  nr
    
    '' Stupid way to do the same thing
    
    :loop
           movs togglepin_ret,#$+2
           jmp #togglepin
           jmp #:loop
    
    togglepin
           xor outa,#1
    togglepin_ret
           jmp #0
    
    
  • Thank you. I saved it as "Wuerfel_21 RET".
    Also thanks for writing "^=" which means 'bitwise XOR'. I was unfamiliar with this symbol.
Sign In or Register to comment.