问题
I need to solve the problem below, but I don't understand the concepts needed for solution.
Let's consider the following string of doublewords: B234*A68C*h, *52B4*78C8h, *1AB3*C470h, F9DC*98B6*h. It is required to:
1) print on the screen the words' ranks that have the minimum value from each doubleword (considering them unsigned)
The answer is '2112' (the bold words have the minimum value)
2) print on the screen the sum of the bytes that have the maximum value from these words (considering them signed)
3) print on the screen the strictly negative *lower words* of the doublewords
How can I differentiate signed from unsigned? What does actually mean negative lower word? Is it a value that doesn't fit in the interval [0, 255]?
回答1:
A word is 16 bits. A doubleword is 32 bits and can be thought of as made up of two individual words.
In a doubleword, the lower word is the low-order word (the one at the lower memory address, since x86 is little-endian). The upper word is the high-order word (the one at the higher memory address).
Registers don't differentiate between signed or unsigned values. There aren't two separate data types as you would normally think of them in a higher-level language. The difference between signed and unsigned only comes into play when you operate on words/doublewords using instructions. There are three classes of instructions:
Unsigned instructions, which treat values in registers/memory as unsigned values. Example:
ja
(jump if above).Signed instructions, which treat values in registers/memory as signed values. Example:
jg
(jump if greater than).Agnostic instructions, which behave in such a way that it doesn't matter whether the values are interpreted as signed or unsigned. Example:
add
(signed and unsigned addition are the same since this is a property of two's-complement arithmetic).
Any reference page/document of x86 instructions should specify whether an instruction is signed or unsigned. If it doesn't specify, the instruction is agnostic.
Hope this helps clarify things a bit!
来源:https://stackoverflow.com/questions/21751959/the-difference-between-signed-and-unsigned-what-means-a-negative-byte