I am trying to create a C program and ASM program to add and subtract two 64 bit numbers. My addition is correct. However, i am having trouble getting the correct output for subtraction. My subtraction function can be seen in my ASM code under subLoop.
Could someone point me in the right direction for subtracting two 64 bit numbers in ASM?
Please note that i am a beginner with C programming, ASM programming, and stackoverflow. I'm very sorry if i didn't format something correctly on this post or in my code
Here is my C Program which is correct:
#include <stdio.h>
#include <stdlib.h>
//C prototype
extern void stats(int[], int, int *, int *);
int main()
{
int lst[] = {0xa, 0x0000000000000005};
int len = 2;
int sum;
int difference;
stats(lst, len, &sum, &difference);
printf("Sum = %x \n", sum);
printf("Difference = %x\n", difference);
return 0;
}
Here is my ASM Program which is half correct (My sumLoop is good, but my subLoop is not):
;------------------------
section .data
;------------------------
section .text
;------------------------
;Call:
; stats(lst, len, &sum, &difference);
global stats
stats:
push r12
;-------------------
mov r11, 0
mov r12d, 0
sumLoop:
mov eax, dword[rdi+r11*4] ;get lst[i]
add r12d, eax ;update sum
inc r11 ;i++
cmp r11, rsi
jb sumLoop
mov dword [rdx], r12d ;return sum
;---------------------
subLoop:
mov eax, dword[rdi+r11*4]
sub r12d, eax
inc r11
cmp r11, rsi
jb subLoop
mov dword [rcx], eax
;----------------------
pop r12
ret