Shop OBEX P1 Docs P2 Docs Learn Events
Question About PASM JMP Instruction — Parallax Forums

Question About PASM JMP Instruction

I found this in the documentation example:

jmp #$ 'don't go wandering off, stay here

I'm assuming the JMP is just jumping back to itself, but I can't find the definition for the "#$" address. Does this mean jump to the address on the program counter (PC) [which would be the address of the current instruction]?

Comments

  • CJMJ wrote: »
    I found this in the documentation example:

    jmp #$ 'don't go wandering off, stay here

    I'm assuming the JMP is just jumping back to itself, but I can't find the definition for the "#$" address. Does this mean jump to the address on the program counter (PC) [which would be the address of the current instruction]?

    $ is what the assembler thinks the address of the current instruction is.
  • CJMJ wrote: »
    I found this in the documentation example:

    jmp #$ 'don't go wandering off, stay here

    I'm assuming the JMP is just jumping back to itself, but I can't find the definition for the "#$" address. Does this mean jump to the address on the program counter (PC) [which would be the address of the current instruction]?

    I recently found the explanation in the Propeller 1 Manual. I recommend that you have it handy until the new manual for Propeller 2 is out.
  • Yep. There it is, on page 298 in the 1.2 version of the Propeller Manual, "The Here Symbol ‘$’". Totally missed this.
    This explanation should definitely be in the P2 manual. Thanks @jrullan.
  • JonnyMacJonnyMac Posts: 8,926
    edited 2020-12-02 19:43
    You can also use that with an offset. I tried this the other day and it work.
                    tjz     x, #$+2                                  ' if x = 0, skip next instruction
                    abs     x
    
    This is one way (of many) to accomplish the same outcome. (BTW, I'm not suggesting this is a practical example, it's just to demonstrate you can make adjustments to #$).
  • and similarly, you can use it to pad to a certain address
            ' pad to 256
            fit 256
            long 0[256-$]
    
  • @Wuerfel_21 I understand your use of the 'Here' symbol in your example but I don't understand your example. I actually had to go find the FIT directive in the P1 manual [which is something else needing to make its way into the P2 manual.

    Here's how I understand your example: The FIT directive makes sure that all preceding instructions and data does not exceed address 256 but I don't understand exactly what the LONG command is doing. Normally you would use it to fill X number of [LONG] memory locations with some Y value.
  • @JonnyMac that would be another example of the 'Here" symbol in the P2 manual.
  • AJLAJL Posts: 515
    edited 2020-12-03 06:35
    CJMJ wrote: »
    @Wuerfel_21 I understand your use of the 'Here' symbol in your example but I don't understand your example. I actually had to go find the FIT directive in the P1 manual [which is something else needing to make its way into the P2 manual.

    Here's how I understand your example: The FIT directive makes sure that all preceding instructions and data does not exceed address 256 but I don't understand exactly what the LONG command is doing. Normally you would use it to fill X number of [LONG] memory locations with some Y value.

    Yes: The X number of longs is 256-$, and the Y value is 0.

    The fit ensures that you aren't going to generate a negative value in the calculation of 256-$.

  • Cluso99Cluso99 Posts: 18,069
    Here is another one for you
                          orgh ($ < $400) ? $400 : $              ' set hub >= $400
    
    It is a verilog style command.

    If the current hub address is < $400 then set the hub address to $400 else leave it as $ (ie current hub address).
    When an orgh $xxx is encountered, pnut zero fills to the new current address (in pasm only code, not sure about spin2). Flexspin also handles this.
  • evanhevanh Posts: 15,187
    edited 2020-12-04 03:27
    That is handy Cluso. I've had an itch for something like that for a while.

    BTW: Verilog most likely borrowed the syntax from C. And given it's not a very C like syntax I'd hazard a guess C borrowed it from an even older language.

  • Wuerfel_21 wrote: »
    and similarly, you can use it to pad to a certain address
            ' pad to 256
            fit 256
            long 0[256-$]
    

    This can also be achieved usng the ORGF directive
        orgf    256
    

  • JonnyMac wrote: »
    You can also use that with an offset. I tried this the other day and it work.
                    tjz     x, #$+2                                  ' if x = 0, skip next instruction
                    abs     x
    
    This is one way (of many) to accomplish the same outcome. (BTW, I'm not suggesting this is a practical example, it's just to demonstrate you can make adjustments to #$).

    Also be aware that when using hubexec the offsets must be scaled for longs.
                    tjz     x, #$+2 * 4                              ' if x = 0, skip next instruction
                    abs     x
    

    [/code]
  • The $ "here" constant is methinks widely used in many assemblers, but I do agree it should be documented somewhere eventually - not everybody using P2 is a veteran :smile:
Sign In or Register to comment.