1

I was researching Brandon W's "fake" application for the ti-84 to see how it worked. (http://brandonw.net/calculators/fake/) While looking through the code I noticed many labels and jump instructions that I didn't understand. I would like to learn how he is using these dollar signs and jumps. My questions are asked in the following code snippet: (All code is from Brandon W's open source fake application!)

    resetKeys:
        xor a
        ld (de),a
$$:     ld a,(MenuCurrent) ;How is this label two dollar signs? What does this mean?
        cp 02h
        jr nz,$F           ;Are we jumping to the instruction at 0xF or to one of these dollar sign labels?
        ld hl,sFakeAppVar
        rst 20h
        B_CALL ChkFindSym
        jr c,$F            ;If we are jumping to 0xF, what are the dollar signs used for?
        ld a,b
        or a
        jr nz,$F
        inc de
        inc de
        ld a,(de)
        cp 25h
        jr z,ignoreAppsKeys
        cp 26h
        jr z,ignoreAppsKeys
        cp 27h
        jr z,ignoreAppsKeys
$$:     pop af              ;Here's another
        ld b,a
        ld a,(cxCurApp)
        cp 45h
        jr nz,$F
        ld a,b
        cp kCapS
        jr nz,$F

From what I have researched, the dollar sign is used when signifying hex or the current location counter. Please correct me if I'm wrong. Any help would be much appreciated!

  • 6
    If I were to hazard a guess `$F` means find the next(`F`orward) `$$` label and branch/jmp to it. I think `$$` acts as a temporary label. It is quite possible that `$B` would go `B`ackward to the previous `$$` label. This is just a guess based on the syntax of some other assemblers. – Michael Petch Feb 14 '16 at 20:27
  • @MichaelPetch Thanks a ton! –  Feb 15 '16 at 02:30
  • 1
    `jr c,$F` is a relative jump if carry flag is one. So if `carry flag == 1` then `PC = PC + 0x0F`. Don't forget that PC will be pointing to the next instruction already so just to be clear it is `PC = address_of_next_instruction + 0x0F`. – GabrielOshiro Feb 16 '16 at 17:48

1 Answers1

2

The $ sign has several uses. Most Z80 assemblers use $ as prefix for hexadecimal numbers, like in this case:

jr z, $2A

These assemblers also use $ to represent the location were present line of code will be in the binary. This is useful to create constants to represent code locations, like in this case:

value_to_jump = $+1
jr $10

In this case, 'value_to_jump' is a constant that will hold the address where $10 is stored (jr $10 is 2-bytes long, so $+1 points to the second of these bytes).

Finally, some assemblers let you create anonymuos labels, like $$ or @@. This is the case you are seeing here. In this code:

jr $f
....
$$:
....
jr $b

Jump instructions mean "closest forward" or "closest backwards", referring to the anonymous labels.

ronaldo
  • 455
  • 3
  • 9