0 和 dword 0 有什么区别? [英] What's the difference between 0 and dword 0?

查看:70
本文介绍了0 和 dword 0 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如问题所述,(例如)mov eax, 0mov eax, dword 0 之间有什么区别?

As the question states, What's the difference between (for example) mov eax, 0 and mov eax, dword 0?

我一直在使用 cmp 语句,但我看不出区别.一个是地址,另一个是数值?

I've been using cmp statements, and I can't catch the difference. Is one an address and the other a numerical value?

推荐答案

它与寄存器没有区别,因为寄存器的名称已经告诉汇编器数据项有多大"(在这种情况下,0) 是:

It does not make a difference with a register since the name of the register already tells the assembler "how big" the data item (in this case, 0) is:

mov   eax, dword 0    ; move a 4-byte 0 into eax
mov   eax, 0          ; move a 0 into eax (eax is 4 bytes, so move 4 bytes)

但是,在某些情况下,您可能希望能够指定值的大小,因为有一个选择.在 x86 32 位汇编中,以下代码会将一个 4 字节的 0 值压入堆栈:

However, there are cases where you might want to be able to specify how large the value is since there's a choice. In x86 32-bit assembly, the following would push a 4-byte 0 value on the stack:

push   0             ; push 4-byte 0 onto the stack

如果你想推送一个 2 字节的 0 值,你可以使用:

If you wanted to push a 2-byte 0 value, you would use:

push   word 0

如果您想明确表示 4 字节的立即推送很清楚,您可以使用 dword:

If you wanted to be explicit so it's clear for the 4-byte immediate push, you could use the dword:

push   dword 0

如果你想把一个立即数移到内存中,那么大小说明符就变得必要了,因为否则汇编器不知道数据项有多大.例如,考虑 nasm 程序集中的以下代码:

If you want to move an immediate value to memory, the size specifier becomes necessary because the assembler doesn't know how large the data item is otherwise. For example, consider the following code in nasm assembly:

        section  .bss
num     resb     4

        ...
        section  .text
        ...
        mov    [num], 0

这会产生一个错误:

 error: operation size not specified

因此您需要指定大小,例如 4 字节:

So you need to specify the size, say, 4-bytes:

        mov    [num], dword 0

这篇关于0 和 dword 0 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆