The program will accept two numbers from the user and display the sum, product, and power (a^b) of those two numbers. Here is the catch, however...
The program MUST: Use an AddNumbers function Use that AddNumbers function in a MultiplyNumbers function Use that MultiplyNumbers function in a CalculatePower function
I cannot figure out how to find the Product of the two numbers by implementing the multiplication through addition function. I cannot grasp the logic behind it. I'm obviously doing something wrong, but I'm not sure what. (Please ignore the inefficiency of the code, I just want to know what I'm doing wrong as far as finding the product of the two)
My code so far..
INCLUDE Irvine32.inc
.data
str1 BYTE "Enter a positive integer: ",0
str2 BYTE "The sum is: ",0
str3 BYTE "The product is: ",0
str4 BYTE "The power result is: ",0
.code
main PROC
call GetInteger
call Crlf
mov eax, ebx
call AddNumbers
mov edx, OFFSET str2
call WriteString
call WriteInt
call Crlf
mov eax, 0
mov ecx, edi
call MultiplyNumber
mov eax, edx
mov edx, OFFSET str3
call WriteString
call WriteInt
call Crlf
call CalculatePower
mov eax, esi
mov edx, OFFSET str4
call WriteString
call WriteInt
call Crlf
exit
main ENDP
GetInteger PROC
mov edx, OFFSET str1
call WriteString
call ReadInt
mov ebx, eax
call WriteString
call ReadInt
mov edi, eax
ret
GetInteger ENDP
CalculatePower PROC USES edi ebx
mov ecx, edi
mov esi, 0
L2:
call MultiplyNumber
add esi, edx
loop L2
ret
CalculatePower ENDP
MultiplyNumber PROC USES ebx edi ecx
mov edx, 0
L1:
mov edi, ebx
mov eax, 0
call AddNumbers
add edx, eax
loop L1
ret
MultiplyNumber ENDP
AddNumbers PROC
add eax, edi
ret
AddNumbers ENDP
END main