variables - x86 汇编要使用哪个变量大小(db、dw、dd)?

标签 variables assembly x86

我不知道所有 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 个字节

来自x86 assembly tutorial ,

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/

相关文章:

assembly - 为什么即使 DPMI 主机处于事件状态,INT 31H 也无法正确设置?

Python如何查找用户输入的字符数

assembly - MIPS 在过程中使用 $s0... 等重新注册并在最后恢复它是否优雅

c - shellcode:将参数传递给 x86_64 程序集中的 execve

c - 获取指令指针指向的给定地址的指令

linux - x86 Linux 汇编程序从_start 获取程序参数

variables - TCL regsub 到变量?

ios - 从 UITableViewCell 分配变量以在主视图 Controller 中发送推文

javascript - 将变量传递到新打开的窗口 - nwj (node-webkit)

assembly - 英特尔开发人员手册中的 "store-buffer forwarding"是什么意思?