assemblyx86flagscpu-registers

Assembly language - Flag setting giving me headaches


I'm trying to determine what various flags should be set to (carry, sign, zero, overflow) after the following operation:

mov ax, 7ff0h;       ax register is now 7ff0h

add al, 10h;         

I'm confused as to how assembly handles this. since we are adding to just the al portion of the register which contains f0h, f0h + 10h gives 100h. Does this set the overflow flag? The carry flag? Neither? I would think the overflow flag would be set, however, another possibility running through my mind is that the program detects this and automatically alters the ah register from 7fh to 80h, making the full ax register 8000h. This would in theory not set the carry flag, but would instead set the sign flag and overflow flag because our overall number 8000h is now negative. could anyone explain how this is handled?

Thanks.


Solution

  • I have played a bit with the debug command (shipped with Intel 32-bit Windows or MS-DOS):

    -a 100
    1A2F:0100 mov ax, 7ff0
    1A2F:0103 add al, 10
    1A2F:0105
    -t =100 2
    
    AX=7FF0  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
    DS=1A2F  ES=1A2F  SS=1A2F  CS=1A2F  IP=0103   NV UP EI PL NZ NA PO NC
    1A2F:0103 0410          ADD     AL,10
    
    AX=7F00  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
    DS=1A2F  ES=1A2F  SS=1A2F  CS=1A2F  IP=0105   NV UP EI PL ZR NA PE CY
    1A2F:0105 0000          ADD     [BX+SI],AL                         DS:0000=CD
    -
    

    NV [No Overflow] PL (positive) CY [Carry]