先谢谢各位。一下是我的程式跟答案
TITLE Chapter 4 Exercise 1 (ch04_01.asm)
Comment !
Description: Write a program that uses addition and subtraction to set and
clear the Carry flag. After each instruction, insert the call DumpRegs
statement to display the registers and flags. Using comments, explain how
(and why) the Carry flag was affected by each instruction.
Author: Tan Deik Hoong
!
INCLUDE Irvine32.inc
.code
main PROC
;adding 1 to 255 rolls AL over to zero:
mov al,255
add al,1 ; AL=0, CF=1 (unsigned overflow)
call DumpRegs
;subtracting larger number from smaller:
sub al,1 ; AL=255, CF=1
call DumpRegs
;subtracting 1 from 255
sub al,1 ; AL=254, CF=0
call DumpRegs
exit
main ENDP
END main
答案:
EAX=75BB1100 EBX=7FFDA000 ECX=00000000 EDX=00401000
ESI=00000000 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=00401009 EFL=00000257 CF=1 SF=0 ZF=1 OF=0 AF=1 PF=1
EAX=75BB11FF EBX=7FFDA000 ECX=00000000 EDX=00401000
ESI=00000000 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=00401010 EFL=00000297 CF=1 SF=1 ZF=0 OF=0 AF=1 PF=1
EAX=75BB11FE EBX=7FFDA000 ECX=00000000 EDX=00401000
ESI=00000000 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=00401017 EFL=00000282 CF=0 SF=1 ZF=0 OF=0 AF=0 PF=0




