I am learning assembly language and got stuck on this point. This is a problem from book "Computer System" chapter 3. The problem description is:
Look at questions A, B and C.
A.
cmpl %eax, %edx
setl %al
Solution: The suffix ‘l’ and the register identifiers indicate 32-bit operands, while the comparison is for a two’s complement ‘<’. We can infer that data_t must be int.
B.
cmpw %ax, %dx
setge %al
Solution: The suffix ‘w’ and the register identifiers indicate 16-bit operands, while the comparison is for a two’s-complement ‘>=’. We can infer that data_t must be short.
C.
cmpb %al, %dl
setb %al
Solution: The suffix ‘b’ and the register identifiers indicate 8-bit operands, while the comparison is for an unsigned ‘<’. We can infer that data_t must be unsigned char.
My question is how to determine "comparison is for a two’s complement ‘<’", "comparison is for a two’s-complement ‘>=’" and "comparison is for an unsigned ‘<’". Also, I cannot understand how to determine data type from this.
The first part (the data type) is straight-forward. eax
is a 32-Bit-register, so the data type is int
(or more precisely int32_t
). Similarly, ax
is a 16 bit register and al
an 8 bit register.
For the second part, you need to know the instructions. The Intel specification says (under the setxx
command):
The terms “above” and “below” are associated with the CF flag and refer to the relationship between two unsigned integer values. The terms “greater” and “less” are associated with the SF and OF flags and refer to the relationship between two signed integer values.
So setb
operates on unsigned values, while setl
and setge
operate on signed values. "two’s complement" here means the same as "signed".