I am trying to convert this code over to arm assembly and am having some trouble with it.
// Multiply with current digit of first number
// and add result to previously stored result
// at current position.
int sum = n1*n2 + result[i_n1 + i_n2] + carry;
// Carry for next iteration
carry = sum/10;
// Store result
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
so far this is what i have, my biggest issue is the portion where it is multiplying
int sum = n1*n2+result[i_n1 + i_n2] + carry
i_n1
and i_n2
are just indexes used to find position in result
n1
and n2
are numbers result
is a pointer to memory. I am also having a smaller issue where the compiler is giving me errors because of how I am using MOD
in ;result[i_n1 + i_n2] = sum % 10;
can someone please let me know what i am doing wrong and how to correct this.
this is what i have so far
;int sum = n1*n2 + result[i_n1 + i_n2] + carry;
ldr r0,=carry
ldr r1,=i_n1
str r1,[r1] ;stores value of r1 into r1
ldr r2,=i_n2
str r2,[r2] ; stores value of r2 in r2
ldr r3,=result
add r4,r1,r2 ; value of i_n1+ value of i_n2
ldr r5,=n2
ldr r6,=n1
mul r7, r5,r6
;carry = sum/10;
mov r1,#10
ldr r2,=sum
sdiv r0,r2,r1 ;divide r2 by r0 sum/10
ldr r3,=carry
str r0,[r3]
;result[i_n1 + i_n2] = sum % 10;
ldr r0,=sum
***mov r1,r0,MOD 10 ;divides r0 by mod 10 and stores remainder in r1*****
ldr r2,i_n1
ldr r3,=i_n2
add r4,r2,r3 ;i_n1+i_n2
ldr r5,=result
str r1,[r5] ;stores value of sum %10 into r5 which is result
;i_n2++;
add r3,#1