标题: Assembly language intel based 关于 Carry Flag [打印本页] 作者: 狂天使 时间: 2010-11-12 12:38 PM 标题: Assembly language intel based 关于 Carry Flag 各位大大,据我所知道的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