Search code examples
assemblyx86nasmmasmirvine32

Assembly bit memory limit in arithmetic


I wanted to add the following numbers: 40, 90, 50 and 155 and I get a total of 355.

I wanted to experiment and test out whether the register AL will have a bit limit of (2^8) - 1, and when I compiled the code and execute the code, I get decimal of 1376331855. How did that happen?

Also, I thought 355 is greater than 255, and as a result should display an overflow exception.

I understand if I use MOVZX I will be able to carry the calculation into the higher register of AX.

Also, I am very confused with the difference between AL and AH. Is there a different in memory allocation for AL and AH?

TITLE Adding              
INCLUDE Irvine32.inc

.code
main PROC

    mov al,0h             ; 
    add al,28h            ; 40

    add al,5Ah            ; 90 
    add al,32h            ;50
    add al,9Bh            ;155
                            ; total is 355
    call DumpRegs
    call writedec

exit
main ENDP
END main

Solution

  • As I understand it, DumpRegs gives you the output of EAX. When I convert your answer to HEX, I get 5209284F, the 4F being in the AL. 4F HEX is 79 Decimal, which is 335 - 256. The AL register only holds 8 bits, so 256 is the maximum unsigned integer it can hold.

    Clear EAX before you begin and the results may make more sense.