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

时间:2013-12-05 19:31:21

标签: assembly

Add #$28,R4,R3 $在此表达式中的含义是什么? R4值是1224,最终结果应该是1264,但是这是如何工作的我不知道。

2 个答案:

答案 0 :(得分:7)

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

  • 前缀数字,表示此数字以十六进制编写。
  • $本身是一个数值表达式,其值为“当前位置”,即下一条指令/数据的汇编地址。

例如:

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)

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

         ;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,'$'

答案 1 :(得分:5)

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

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

相关问题