Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with overflow/carry

Status
Not open for further replies.

vivendi

Programmer
May 12, 2005
34
Hello, i have to calculate the sum of numbers, which works great, but now i have to do this with numbers that are to big so that a carry is set.
Somehow i still have to display the real result, but i dont know how to do this when there's an overflow/carry.
I know i have to use the JC instruction to see if a carry is set, but i dont know what to do with it and how to handle after a carry is set. Can someone please help me out with this!?

I've got the following sourcecode.

Code:
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib	\masm32\lib\kernel32.lib
includelib	\masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib


.data
    numbers dd 2000000001,2000000002,2000000003,2000000004,2000000005
    message db "Total is %d",0
    testmsg    db "Carry is set",10,13


.data?
    buffer  db 100 dup(?)


.code

start:

    xor     eax,eax
    mov     edx,OFFSET numbers
    mov     ecx,5
Count:
    add     eax,DWORD PTR [edx]
    add     edx,4
                                
    dec     ecx
    jnz     Count

    invoke  wsprintf,ADDR buffer,ADDR message,eax
    invoke  StdOut,ADDR buffer
    invoke  ExitProcess,0        

END	start
 
You don't need a jump. If you need to add numbers big enough to create a carry, you can use the carry in subsequent additions with adc instead of add.

Think decimal:

13 + 28:

add 3 + 8 = 1 (and carry is set) = low digit
adc 1 + 2 + carry = 4 = high digit


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top