上表是 32 位寄存器 EFLAGS 的低 16 位.
不能直接讀寫 EFLAGS, 但有些方便的指令, 如:
LAHF: 讀取EFLAGS 低 8 位到 AH; SAHF 是 LAHF 的反向操作.
指令 STC、CLC、CMC 分別是給 CF(進位標志) 置位、復位、取反
; Test20_1.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
szBin1 db 8 dup(?), 0
szBin2 db 8 dup(?), 0
szBin3 db 8 dup(?), 0
szBin4 db 8 dup(?), 0
.code
main proc
stc ;置位 CF, CF = 1
lahf
invoke byt2bin_ex, ah, addr szBin1
clc ;復位 CF, CF = 0
lahf
invoke byt2bin_ex, ah, addr szBin2
stc
cmc ;取反 CF, CF = not CF
lahf
invoke byt2bin_ex, ah, addr szBin3
clc
cmc ;取反 CF, CF = not CF
lahf
invoke byt2bin_ex, ah, addr szBin4
PrintString szBin1 ;xxxxxxx1
PrintString szBin2 ;xxxxxxx0
PrintString szBin3 ;xxxxxxx0
PrintString szBin4 ;xxxxxxx1
ret
main endp
end main
如果要觀察整個 EFLAGS 的 32 個位, 可用 PUSHFD 和 POPFD 指令讓 EFLAGS 進棧、出棧
; Test20_2.asm
.586p
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
szBin db 32 dup(?), 0
.code
main proc
stc
pushfd
invoke dw2bin_ex, dWord ptr [esp+4], addr szBin
popfd
PrintString szBin ;00000000000000000000001001000111
clc
pushfd
invoke dw2bin_ex, dWord ptr [esp+4], addr szBin
popfd
PrintString szBin ;00000000000000000000001010000110
ret
main endp
end main
發現標志寄存器裡的數據有點捉摸不定, 看來不應該是這麼觀察的; 以後慢慢留意吧.