Unsigned integers in assembly

时光怂恿深爱的人放手 提交于 2020-11-28 08:35:29

问题


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

Using:

Linux

NASM

x86 (32 Bit)

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?


回答1:


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.

The 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", that's nonsense. It can only appear negative if you chose to interpret it that way.



来源:https://stackoverflow.com/questions/42795616/unsigned-integers-in-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!