net_man
net_man

Reputation: 49

Changing the value of signed bit after substraction

i wrote this part of code in 16 bit assembler x86:

mov dl, F3h
mov bh, 72h
sub dl, bh

When I was debugging code in turbo debugger i found out, that after sub dl, bh the signed flat changed to 1, bud signed flag is set to 1 if result of operation is negative so why is signed flat set to 1 in this case, when result would be positive?

Upvotes: 0

Views: 43

Answers (1)

Ross Ridge
Ross Ridge

Reputation: 39621

The result of F3h - 72h is 81h. Since sub dl, bh is an 8-bit operation the sign bit is the eighth bit of the value (where the first bit of the value is the lowest order bit). Since the eight bit of the result 81h is set, the sign flag is set. When the unsigned value 81h is interpreted as a signed 8-bit value it becomes the negative number -7F (-127).

Upvotes: 3

Related Questions