x86汇编 - 要使用的可变大小(DB,DW,DD) [英] x86 assembly - Which variable size to use (db, dw, dd)
问题描述
我是一个初学者到组装,我不知道所有的DB,DW,DD,事情的意思。
我试图写这个小脚本,做1 + 1,并将其存储在一个变量,然后显示结果。这里是我的code迄今:
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 \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
我需要了解哪些数据库,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.
在此先感谢,
Progrmr
Thanks in advance, Progrmr
推荐答案
DB - 定义字节。 8位
DB - Define Byte. 8 bits
DW - 定义字。一般一个典型的x86 32位系统上2个字节
DW - Define Word. Generally 2 bytes on a typical x86 32-bit system
DD - 定义双字。一般一个典型的x86 32位系统上的4个字节
DD - Define double word. Generally 4 bytes on a typical x86 32-bit system
组装教程,
POP指令的删除从顶部的4个字节的数据元素
支持的硬件堆栈到指定的操作数(即寄存器
或存储器位置)。它首先移动位于内存中的4个字节
位置[SP]到指定的寄存器或存储器位置,然后
4 SP递增
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.
您num是1个字节。试着用 DD
,使之成为4个字节,用弹出
语义匹配。
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屋!