My program is one in which i add consecutive odd numbers n number of times. (the pattern is that the resulting sum is always n*n). However, I am supposed to use 10,000 as n with the sum in the ax register. This program is linked to a c file in which the sum is outputted to the screen by: printf("Sum is %d", sum);
The answer I get is -7936. I think this is because there is an overflow problem and the comp is reading the sum as a signed number. Smaller numbers such as 39 work correctly. Does anyone know how to solve this problem and output the correct answer: 100000000?? thanks!
Comments
: The answer I get is -7936. I think this is because there is an overflow problem and the comp is reading the sum as a signed number. Smaller numbers such as 39 work correctly. Does anyone know how to solve this problem and output the correct answer: 100000000?? thanks!
:
[blue]1. You need to use [b]long[/b] as your return type from your ASM function, so "C" compiler will know what to expect.
2. Your ASM function should return two registers: DX:AX - full 32 bit of the result.
3. Here is the code which will add [b]long[/b] values in ASM:[/blue][code]
; --- Clear the accumulator:
xor dx, dx
xor ax, ax
; --- Add value in CX into accumulator:
add ax, cx
adc dx, 0
[/code]