我是汇编的初学者,我不知道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 …Run Code Online (Sandbox Code Playgroud) 我需要帮助理解x86处理器的CPU寄存器内的字节序.我写了这个小装配程序:
section .data
section .bss
section .text
global _start
_start:
nop
mov eax, 0x78FF5ABC
mov ebx,'WXYZ'
nop ; GDB breakpoint here.
mov eax, 1
mov ebx, 0
int 0x80
Run Code Online (Sandbox Code Playgroud)
我在GDB中使用第10行的断点运行此程序(在上面的源代码中注释).在此断点,info registers显示的数值eax=0x78ff5abc和ebx=0x5a595857.
由于W,X,Y,Z的ASCII码分别为57,58,59,5A; 并且intel是小端,0x5a595857似乎是正确的字节顺序(最低有效字节优先).那么为什么不是eax寄存器的输出0xbc5aff78(数字0x78ff5abc的最低有效字节)而不是0x78ff5abc?
在以下 x86 汇编代码中:
dd 0x1BADB002
dd 0x00
dd - (0x1BADB002+0x00)
Run Code Online (Sandbox Code Playgroud)
这些值似乎没有分配给任何变量。那么这段代码有什么作用呢?我听说过它被存储在内存中,但具体在哪里呢?
我正在按照教程在汇编中编写一个hello world bootloader,我正在使用NASM汇编程序来安装x-86机器.这是我正在使用的代码:
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV SI, HelloString ;Store string pointer to SI
CALL PrintString ;Call print string procedure
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E ;Tell BIOS that we need to print one …Run Code Online (Sandbox Code Playgroud) 我正在尝试研究在汇编中定义标签之间的区别,这是一个示例
ALabel: db 'Testing'
AAnotherLabel: dw 'Testing'
Run Code Online (Sandbox Code Playgroud)
现在,让我将它们加载到32位寄存器中:
mov eax, [ALabel]
mov ebx, [AAnotherLabel]
Run Code Online (Sandbox Code Playgroud)
在对gdb进行调查后,我发现eax和ebx的所有子寄存器都包含相同的值,请看这里:
info register eax
0x64636261 //dcba
info register ebx
0x64636261 //dcba
Run Code Online (Sandbox Code Playgroud)
他们是一样的!
在杰夫·邓特曼(Jeff Duntemann)的书(使用Linux进行汇编语言逐步编程)中,他展示了单词和双字进入寄存器的示例,但由于某种原因加载了偏移量(即,值的地址类似)
DoubleString: dd 'Stop'
mov edx, DoubleString
Run Code Online (Sandbox Code Playgroud)
对edx内容的调查表明,它包含一个地址,大概是字符串中前四个字母的地址,与仅第一个字母的地址相对应,尽管我在这里进行了推测。
我想弄清楚这里实际发生的情况,实际上是该语句是否将字符串中第一个字母的地址加载到寄存器中:
Fin: db 'Final'
mov ecx, Fin
Run Code Online (Sandbox Code Playgroud) 我的意思是我在 NASM 中这样写的东西:
mov dword [0xA0BF17C], ' : )'
Run Code Online (Sandbox Code Playgroud)
我在 GNU 汇编程序中尝试过这样的事情:
movd " : )", 0xB8000
movd $" : )", 0xB8000
movd ' : )', 0xB8000
movd " : )", $0xB8000
Run Code Online (Sandbox Code Playgroud)
但是......他们都导致了这个错误:
Error: unbalanced parenthesis in operand 1.
Run Code Online (Sandbox Code Playgroud) 我想知道使用 MOV 指令将字符串复制到寄存器中是否会导致字符串以相反的顺序存储。我了解到,当 MASM 将字符串存储到定义为单词或更高(dw 和更大尺寸)的变量中时,字符串以相反的顺序存储。当我将字符串复制到寄存器时会发生同样的事情吗?
基于这个问题(关于 SCAS 指令以及关于在 MASM 32 中为变量分配字符串和字符)我假设如下:
str dd "abc"导致 MASM 将字符串存储为“cba”,这意味着“c”位于最低的内存地址中。str db "abc"MASM 时,将其str视为字符数组。尝试将数组索引与 的内存地址匹配str,MASM 将在 的最低内存地址处存储“a” str。当我一个字节数组传递arLetters与字符“a”,“b”和“c”来的双字变量strLetters使用MOVSD,相信的字母被复制到strLetters在反向,即作为“CBA”存储。当我使用mov eax, "abc"时,字母是否也以相反的顺序存储?
下面的代码将在退出之前设置零标志。
.data?
strLetters dd ?,0
.data
arLetters db "abcd"
.code
start: …Run Code Online (Sandbox Code Playgroud)