Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1508|回复: 2
打印 上一主题 下一主题

Assembly language intel based 关于 Carry Flag

[复制链接]

23

主题

0

好友

122

积分

高级会员

Rank: 3Rank: 3Rank: 3

跳转到指定楼层
1#
发表于 2010-11-12 12:38 PM |只看该作者 |倒序浏览
各位大大,据我所知道的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




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2010-11-12 03:02 PM |只看该作者
本帖最后由 Super-Tomato 于 2010-11-12 03:12 PM 编辑
各位大大,据我所知道的Carry Flag 应该是在unsigned 的的type是当通过加减而超过本身 type 的容量那时才会 ...
狂天使 发表于 2010-11-12 12:38 PM




你說的检查 sign 与 unsigned 應該是 SF 才對吧,CF 則是在 binary 情况下造成最左边第一個 bit 有带動下就會是 1


p/s: 自己看看說明 http://www.c-jump.com/CIS77/ASM/Flags/lecture.html


回复

使用道具 举报

23

主题

0

好友

122

积分

高级会员

Rank: 3Rank: 3Rank: 3

3#
发表于 2010-11-12 08:23 PM |只看该作者
回复 2# Super-Tomato


谢谢回复,明白了。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 06:29 PM , Processed in 0.105593 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部