- 分享
- 0
- 人气
- 0
- 主题
- 23
- 帖子
- 124
- UID
- 186218
- 积分
- 122
- 阅读权限
- 13
- 注册时间
- 2008-12-16
- 最后登录
- 2012-3-17
- 在线时间
- 358 小时
|
各位大大,据我所知道的Carry Flag 应该是在unsigned 的的type是当通过加减而超过本身 type 的容量那时才会出现”1“。8bit 的 register 最大的数字应该是 255 但是我从255 加到256 然后再减1 变回255 那时为什么CF 还是会一呢?而且SF 也是有1.应该是正数的,不同为什么SF会出现1.
先谢谢各位。一下是我的程式跟答案
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 |
|