MOV 和 MOV ptr 的区别
Difference between MOV and MOV ptr
我不明白 MOV
和 MOV ptr
之间的区别。
例如,在这个 C
代码中:
unsigned char x, y;
x = 2;
汇编中的第二行是:
`MOV x, 2`
但是这个 C
代码的第二行:
tabbyte[0] = 15
unsigned char tabbyte[4]
在汇编中是:
MOV byte ptr tabbyte[0], 15
两条汇编指令有什么区别,应该在什么时候使用?
Directives BYTE PTR, WORD PTR, DWORD PTR
There are times when we need to assist assembler in translating references to data in memory.
For example, instruction
mov [ESI], al ; Store a byte-size value in memory location pointed by ESI
suggests that an 8-bit quantity should be moved because AL is an 8-bit register.
When instruction has no reference to operand size,
mov [ESI], 5 ; Error: operand must have the size specified
To get around this instance, we must use a pointer directive, such as
mov BYTE PTR [ESI], 5 ; Store 8-bit value
mov WORD PTR [ESI], 5 ; Store 16-bit value
mov DWORD PTR [ESI], 5 ; Store 32-bit value
These instructions require operands to be the same size.
In general, PTR operator forces expression to be treated as a pointer of specified type:
.DATA
num DWORD 0
.CODE
mov ax, WORD PTR [num] ; Load a word-size value from a DWORD
http://www.c-jump.com/CIS77/ASM/Instructions/I77_0250_ptr_pointer.htm
byte ptr
、word ptr
等只需要在操作数没有隐含的情况下表示要运算的大小。它是方括号([
和 ]
),在 MASM 中是表示内存引用的裸符号。要在 MASM 中使用变量的地址,请在其前面加上 offset
,对于 NASM,只需省略方括号。
Intel 语法模式下的 GNU AS 在这方面表现得像 MASM。
我不明白 MOV
和 MOV ptr
之间的区别。
例如,在这个 C
代码中:
unsigned char x, y;
x = 2;
汇编中的第二行是:
`MOV x, 2`
但是这个 C
代码的第二行:
tabbyte[0] = 15
unsigned char tabbyte[4]
在汇编中是:
MOV byte ptr tabbyte[0], 15
两条汇编指令有什么区别,应该在什么时候使用?
Directives BYTE PTR, WORD PTR, DWORD PTR
There are times when we need to assist assembler in translating references to data in memory.
For example, instruction
mov [ESI], al ; Store a byte-size value in memory location pointed by ESI
suggests that an 8-bit quantity should be moved because AL is an 8-bit register.
When instruction has no reference to operand size,
mov [ESI], 5 ; Error: operand must have the size specified
To get around this instance, we must use a pointer directive, such as
mov BYTE PTR [ESI], 5 ; Store 8-bit value mov WORD PTR [ESI], 5 ; Store 16-bit value mov DWORD PTR [ESI], 5 ; Store 32-bit value
These instructions require operands to be the same size.
In general, PTR operator forces expression to be treated as a pointer of specified type:
.DATA num DWORD 0 .CODE mov ax, WORD PTR [num] ; Load a word-size value from a DWORD
http://www.c-jump.com/CIS77/ASM/Instructions/I77_0250_ptr_pointer.htm
byte ptr
、word ptr
等只需要在操作数没有隐含的情况下表示要运算的大小。它是方括号([
和 ]
),在 MASM 中是表示内存引用的裸符号。要在 MASM 中使用变量的地址,请在其前面加上 offset
,对于 NASM,只需省略方括号。
Intel 语法模式下的 GNU AS 在这方面表现得像 MASM。