Search code examples
assemblyintegermathunsignedsigned

would doing arithmetic operation on a pair of signed and unsigned numbers be legal?


I'm more than half way through learning assembly and I'm familiar with the concept of how signed and unsigned integers are presented in bits, I know that it might seem a weird question of which the answer would be pretty obvious, but I'm wondering if using an arithmetic operation like addition makes sense for a pair of numbers that one of them is considered signed and the other one unsigned, I've thought of multiple examples like below that will yield a correct result:

10000001 (1-byte integer and considered unsigned, equivalent to 129)
+
11111111 (1-byte integer and considered signed(two's complement system), equivalent to -1)


10000000 (1-byte integer and in unsigned logic equivalent to 128)

Now if the upper value was in AL register and we had the following instruction code(in GAS format):

addb -1, %al

then the carry flag(CF) of EFLAGS register will be set after the operation's been done and would inform of an overflow that actually has not happened and maybe because there's one unsigned number in terms of an overflow the overflow flag(OF) of EFLAGS register should be referenced. So I'm confused if doing such thing is ever sensible.


Solution

  • I found this very nice article on the issue that was my main concern and the answer is clear after reading the article.