What does $ mean in MIPS assembly?

In assemblers, symbol $ usually means two different things:

  • Prefixing a number, means that this number is written in hexadecimal.
  • By itself, $ is a numeric expression that evaluates as "the current position", that is, the address where the next instruction/data would be assembled.

For example:

mydata:     db 0,1,2,3,4,5,6,7,8,9,$a,$b,$c,$d,$e,$f   ;some decimal and 
                                                      ;hexadecimal numbers
datalenght  equ $-mydata   ;length of previous list.

            jmp $          ;an infinite loop!! ($ evaluates as the current 
                           ;                     position just before the 
                           ;                     instruction is assembled, 
                           ;                     that is, the position where 
                           ;                     the JMP instruction begins)

You might also see $ at the end of string constants, as a string terminator character if you write or read programs written for CP/M or MS DOS. Both OS used this convention, so the system call to print a string to the console expects a dollar-terminated string. Gary Kildall, the creator of CP/M, never disclosed why he had chosen that particular symbol for marking the end of a string.

         ;A very simple MSDOS program to 
         ;display "Hello world" to console.
         org 100h   
         mov dx,offset Message
         mov ah,9
         int 21h
         int 20h
Message: db "Hello, world!",13,10,'$'

         ;A very simple CP/M program to 
         ;display "Hello world" to console.
         org $100
         mov de,Message
         mov c,9
         call 5  ;call bdos
         rst 0
Message: db "Hello, world!",13,10,'$'

In some assemblers, the '$' means simply that you are using a hex value. on the x86 architecture it usual to write the number with 'h' or if the first character is not a digit, then you have to use a zero in front 28h or 0afh. In C you would write 0x28.

For example on the 6510 (Commodore 64) or M68000 (i.e. Amiga) the '$' character was used for this like '$28'. I'm sure there are other assemblers as well using this notation.

Tags:

Assembly

Mips