x86 程序集使用哪个可变大小(db、dw、dd)? [英] Which variable size to use (db, dw, dd) with x86 assembly?

查看:17
本文介绍了x86 程序集使用哪个可变大小(db、dw、dd)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是组装的初学者,我不知道所有的 db、dw、dd 是什么意思.我曾尝试编写这个执行 1+1 的小脚本,将其存储在一个变量中,然后显示结果.到目前为止,这是我的代码:

I am a beginner to assembly and I don't know what all the db, dw, dd, things mean. I have tried to write this little script that does 1+1, stores it in a variable and then displays the result. Here is my code so far:

.386
.model flat, stdcall 
option casemap :none
include masm32includewindows.inc
include masm32includekernel32.inc
include masm32includemasm32.inc
includelib masm32libkernel32.lib
includelib masm32libmasm32.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 的含义以及它们如何影响变量设置和组合等等.

I need to understand what the db, dw, dd things mean and how they affect variable setting and combining and that sort of thing.

提前致谢,程序

推荐答案

快速回顾,

  • DB - 定义字节.8位
  • DW - 定义 Word.在典型的 x86 32 位系统上通常为 2 个字节
  • DD - 定义双字.在典型的 x86 32 位系统上通常为 4 个字节
  • DB - Define Byte. 8 bits
  • DW - Define Word. Generally 2 bytes on a typical x86 32-bit system
  • DD - Define double word. Generally 4 bytes on a typical x86 32-bit system

来自 x86 组装教程

pop 指令 从顶部移除 4 字节的数据元素硬件支持的堆栈到指定的操作数(即寄存器或内存位置).它首先移动位于内存中的 4 个字节location [SP] 放入指定的寄存器或内存位置,然后将 SP 增加 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 语义匹配.

Your num is 1 byte. Try declaring it with DD so that it becomes 4 bytes and matches with pop semantics.

这篇关于x86 程序集使用哪个可变大小(db、dw、dd)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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