简体   繁体   中英

assembly 8086 carry flag - signed number how minus equals plus

I dont understood something. This the question:

mov  al,-128d
mov  ah,40d
add  al,ah ;result is out of 8 bit unsigned range?

why carry flag dont turn on? it's need to be 88, 88 don't in the range of 0-255!

why the number little d in the end and not with little h? its decimal number?

why -128 + 40 equals 168 ?

How is it possible?

Yes, the small "d" after digits means "decimal", so mov al,-128d is same as mov al,-128 or mov al,-80h .

I don't understand that part of question with 88.

About add al,ah :

It will do al = al + ah . Both registers are 8 bit "wide", and their content is (binary) AL = 10000000, AH = 00101000 . Result of such addition is in binary 10101000 = 168 in decimal, when interpreted as 8 bit unsigned value.

But when you try to interpret the same value as 8 bit signed value, it is equal to -88 .

The ADD itself, or the registers AL / AH do not understand your interpretation, they don't care, the ADD will do simple bit addition, and the CF is set when the last addition of top bit did overflow, which it didn't in this case (if the AL is interpreted as unsigned 8 bit value, it is equal to +128, and 128 + 40 = 168 => didn't exceed 255 => carry flag = 0).

Actually the result is neither out of 8 bit unsigned or signed range, the result is correct value 168 or -88, depending on which way you interpret it (as unsigned or signed), it's the same value in the AL . How you read/interpret it depends on the following code.

To have some unsigned 8b arithmetic going out of range, you need the result to be over 255, ie

    mov  al,150  ; binary 1001 0110
    mov  ah,150
    add  al,ah   ; al = 44 (low 8 bits of value 300), CF=1 (like 9th bit for ADD)
    ; 300 is in binary 0000 0001 0010 1100 (needs at least 9 bits)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM