<<< CLC, STC, CMC - Direct Carry Flag Manipulation | Index | The LAHF and SAHF Instructions >>> |
Examples of 8-bit signed and unsigned addition and subtraction:
.DATA mem8 BYTE 39 ; 0010 0111 27 ; .CODE ; Addition + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ; signed unsigned binary hex mov al, 26 ; Start with register 26 26 0001 1010 1A inc al ; Increment +1 +1 ; ---- ---- ; 27 27 0001 1011 1B add al, 76 ; Add immediate +76 +76 0100 1100 4C ; ---- ---- ; 103 103 0110 0111 67 add al, [mem8] ; Add memory +39 +39 0010 0111 27 ; ---- ---- mov ah, al ; Copy to AH -114 142 1000 1110 8E (OF) (SF) add al, ah ; Add register + -114 +142 1000 1110 8E ; ---- ---- ; 28 28 0001 1100 1C (OF) (CF) ; Subtraction- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; signed unsigned binary hex mov al, 95 ; Load register 95 95 0101 1111 5F dec al ; Decrement - 1 - 1 ; ---- ---- ; 94 94 0101 1110 5E sub al, 23 ; Subtract immediate - 23 - 23 1110 1001 E9 ; ---- ---- ; 71 71 0100 0111 47 mov [mem8],122 ; Load memory sub al, [mem8] ; Subtract memory - 122 - 122 0111 1010 7A ; ---- ---- ; -51 205 1100 1101 CD (SF) (CF):borrow mov ah, 119 ; Load register sub al, ah ; and subtract - 119 - 119 0111 0111 77 ; ---- ---- ; 86 86 0101 0110 56 (OF)
(OF) overflow flag indicates that result is too large to fit in the 8-bit destination operand:
the sum of two positive signed operands exceeds 127.
the difference of two negative operands is less than -128.
(CF) carry flag indicates that the sum of two unsigned operands exceeded 255.
(SF) sign flag indicates that result goes below 0.
To verify the above conditions, try ADD_SUB_EFLAGS.exe demo program ADD_SUB_EFLAGS.ASM ( download source here.)
<<< CLC, STC, CMC - Direct Carry Flag Manipulation | Index | The LAHF and SAHF Instructions >>> |