【发布时间】:2017-05-12 18:24:44
【问题描述】:
我正在阅读 Duntemann 的书(第 3 版)并且刚刚开始学习 x86 汇编。我正在使用 Fedora 23(64 位)的变体。以下是代码:
section .data
section .text
global _start
_start:
nop
; Put your experiments between the two nops...
mov eax,0FFFFFFFFh
mov ebx,02Dh
dec ebx
inc eax
; Put your experiments between the two nops...
nop
我的makefile如下:
sandbox: sandbox.o
ld -o sandbox sandbox.o -melf_i386
sandbox.o: sandbox.asm
nasm -f elf -g -F stabs sandbox.asm -l sandbox.lst
所以你可以看到我已经小心地组装了一个 32 位的可执行文件,而不是 64 位的。然而,问题在于,在dec ebx 指令之前,AF 和SF 标志的设置并未与书中声称的相反。在insight 中运行程序会显示 32 位寄存器,这进一步确保了可执行文件是 32 位的。以下是gdb 在dec ebx 指令之前显示的状态。
(gdb) info reg
eax 0xffffffff -1
ecx 0x0 0
edx 0x0 0
ebx 0x2d 45
esp 0xffffce80 0xffffce80
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x804806b 0x804806b <_start+11>
eflags 0x202 [ IF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x0 0
Pg 217 中的 Duntemann 版本显示设置了 AF 和 SF 标志。我的代码有什么问题?
【问题讨论】:
-
movs 不设置标志。谷歌“intel manual 2”的官方文档,其中包含受它们影响的说明和标志