美元在装配中意味着什么?

Mar*_*aht 4 assembly mips

Add #$28,R4,R3$这个表达意味着什么?R4值是1224,最终结果应该是1264,但是这是如何工作的我不知道.

mcl*_*fix 8

在汇编程序中,符号$通常表示两种不同的东西:

  • 前缀数字意味着此数字以十六进制表示.
  • 就其本身而言,$是一个数值表达式,其值为"当前位置",即下一条指令/数据的汇编地址.

例如:

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)
Run Code Online (Sandbox Code Playgroud)

如果您编写或读取为CP/M或MS DOS编写的程序,您可能还会在字符串常量的末尾看到$,作为字符串终止符.两个操作系统都使用了这种约定,因此系统调用将字符串打印到控制台需要以美元结尾的字符串.CP/M的创造者加里·基尔达尔(Gary Kildall)从未透露过为什么他选择了特定的符号来标记字符串的结尾.

         ;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,'$'
Run Code Online (Sandbox Code Playgroud)
         ;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,'$'
Run Code Online (Sandbox Code Playgroud)


Dev*_*lus 6

在某些汇编程序中,'$'表示您使用的是十六进制值.在x86架构上通常用'h'来写数字,或者如果第一个字符不是数字,那么你必须在前面28h或后面使用零0afh.在C中你会写0x28.

例如在6510(Commodore 64)或M68000(即Amiga)上,'$'字符用于此类似'$ 28'.我确信还有其他装配工使用这种表示法.