我不知道所有 db、dw、dd 等东西的含义是什么。 我尝试编写这个执行 1+1 的小脚本,将其存储在变量中,然后显示结果。这是到目前为止我的代码:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
num db ? ; set variable . Here is where I don't know what data type to use.
.code
start:
mov eax, 1 ; add 1 to eax register
mov ebx, 1 ; add 1 to ebx register
add eax, ebx ; add registers eax and ebx
push eax ; push eax into the stack
pop num ; pop eax into the variable num (when I tried it, it gave me an error, i think thats because of the data type)
invoke StdOut, addr num ; display num on the console.
invoke ExitProcess ; exit
end start
我需要了解 db、dw、dd 的含义以及它们如何影响变量设置和组合之类的事情。
最佳答案
快速审查,
- DB - 定义字节。 8位
- DW - 定义单词。在典型的 x86 32 位系统上通常为 2 个字节
- DD - 定义双字。在典型的 x86 32 位系统上通常为 4 个字节
The pop instruction removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location). It first moves the 4 bytes located at memory location [SP] into the specified register or memory location, and then increments SP by 4.
你的数字是1字节。尝试使用 DD
声明它,使其变为 4 个字节并与 pop
语义匹配。
关于variables - x86 汇编要使用哪个变量大小(db、dw、dd)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10168743/