汇编中的无符号整数 [英] Unsigned integers in assembly

查看:34
本文介绍了汇编中的无符号整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新的汇编需要一些无符号算术方面的帮助.从 C 程序转换是什么意思.

Brand new to assembly need some help with unsigned arithmetic. Converting from a C program is that means anything.

使用:

Linux

NASM

x86(32 位)

我想从用户那里读入一个数字.我希望这个数字是无符号的.当我输入一个高于有符号整数限制的数字并使用信息寄存器时,我注意到我的寄存器存储为负数,这意味着发生了溢出.(显然输入的数字低于 max unsigned int)我如何将此寄存器视为无符号,以便我可以根据结果进行比较和跳转?

I want to read in a number from the user. I want this number to be unsigned. When I enter a number above the signed integer limit and use info registers, I notice that my register storing that is negative which means an overflow happened. (Obviously number entered is below max unsigned int) How do I treat this register as unsigned so I can do comparisons and jump based on the result?

推荐答案

在汇编中,没有不同的有符号和无符号类型.寄存器保存的值可以是有符号的也可以是无符号的,这取决于您如何看待它.

In assembly, there are no distinct signed and unsigned types. A register holds a value that can be either signed or unsigned, depending on how you look at it.

有与有符号解释一致的指令(jgjl等)和与无符号解释一致的指令(jajb 等)cmp 指令对两者都有效——它设置了可以被 jl 之类的指令用来跳转的标志基于有符号解释,以及jb等指令可以使用的标志,以根据无符号解释跳转.无论您没有使用哪个标志,您都可以忽略.

There are instructions that are consistent with the signed interpretation (jg, jl, etc.) and instructions that are consistent with the unsigned interpretation (ja, jb, etc.) The cmp instruction works for both - it sets flags that can be used by instructions like jl to jump based on the signed interpretation, and flags that can be used by instructions like jb to jump based on the unsigned interpretation. Whichever flags you're not using, you just ignore.

因此,当您说我的寄存器存储为负数"时,这是没有意义的.如果你选择这样解释,它只会显得消极.

So when you say "my register storing that is negative", it makes no sense. It can only appear negative if you chose to interpret it that way.

这篇关于汇编中的无符号整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆