assembly - 如何设置进位标志添加两个数字(32位)
问题描述
我使用 read_int 得到了两个数字,并添加了两个数字。最后我检查了 EFLAGS (dump_regs)。
所以,要设置进位标志,我尝试了“4,294,967,295 + 1”,但是没有设置进位标志。('CF'没有显示在屏幕上)
如果我想设置进位标志,我需要什么数字?
call read_int
mov ebx, eax
call read_int
mov ecx, eax
mov edx, ebx ; add the two numbers, edx = ebx - ecx
add edx, ecx
mov eax, edx
call print_int
call print_nl
dump_regs 1
我输入了 4294967295 和 1
解决方案
如果您运行以下代码,您可以说服自己设置了进位标志:
call read_int ;Input say 150
mov ebx, eax
call read_int ;Input say 180
add al, bl ;This produces a carry because 150+180=330 DOESN'T FIT the 8-bit register AL
setc al ;AL becomes 1
movzx eax, al ;EAX becomes 1
call print_int ;Show it
使用不产生进位的数字进行验证:
call read_int ;Input say 80
mov ebx, eax
call read_int ;Input say 125
add al, bl ;This produces NO carry because 80+125=205 DOES FIT the 8-bit register AL
setc al ;AL becomes 0
movzx eax, al ;EAX becomes 0
call print_int ;Show it
推荐阅读
- java - 如何根据特定键在 MongoDB 中获取最大值和最小值?
- javascript - 2D 重叠矩形遮挡
- javascript - 当我依赖 usePrevious 时,如何停止组件中的额外重新渲染?
- makefile - 如何在多行 Makefile 变量中包含以“define”开头的字符串?
- node.js - Next.js 在安装时向我显示此错误
- twincat - TwinCAT 无法将数据保存到 CSV
- javascript - 如何对第三方 javascript 文件进行数字签名或验证?
- html - 如何使用带有 jQuery 的 Bootstrap Cards 来缓解 DRY
- unix - 在 Unix Shell 脚本中需要帮助
- spring-boot - 是否有任何特定方法可以使用 H2 数据库对多个数据库进行 spring-boot junit 测试