I am brand new to this language and my task is to create a program with 3 procedures. One procedure which asks the user for a number, another procedure which finds the factorial of that number, and a final procedure to print the information.
I wrote the first procedure and I'm now up the the hard part, finding the factorial.
I believe I have the correct code for the most part but when trying to pass the procedure with the input from user, I run into errors.
Here is my code (I tried to put as many notes as possible so you can see where my head is at just in case I'm on the wrong track) :
include c:\asmio\asm32.inc
includelib c:\asmio\asm32.lib
includelib c:\asmio\User32.lib
includelib c:\asmio\Kernel32.lib
input proto ; 0 parameters
Factorial proto nv: dword ; 1 parameter
; -------------------------------------------------------
.const
NULL = 0
; -------------------------------------------------------
.data
nvx dword ? ;
ask byte "Enter a number between 1-12: ", NULL
; -------------------------------------------------------
.code
main proc
invoke input ; gets input from user, see procedure below
mov nvx, eax ; after first procedure, moves given input from user into variable
invoke Factorial nvx: dword ; This is where my error is according to compiler
ret 0
main endp
; -------------------------------------------------------
input proc
mov edx, OFFSET ask
call WriteString
call ReadInt
ret
input endp
; -------------------------------------------------------
Factorial proc USES ECX EAX EBX nv: dword
mov ecx, nv ;start loop counter at value given by user because we need to multiply this many times to find the factorial.
mov ebx, nv ; hold value of nv as divisor
inc nv ; This is to account for 0! We increment by one and after the loop divide by nv
mov eax, nv ; stores the largest number for multiplication
L1:
dec nv ; becomes next largest number
mul nv ; multiplication
mov eax, edx ; stores product into eax for next multiplication
loop L1
cdq
idiv ebx ; divide final product by original number entered for the correct factorial
ret
Factorial endp
end main ; End of the entire program
; -------------------------------------------------------
Here is my error log:
[11:20:28] Build started...
[11:20:28] Warning! Errors have occurred in the build:
Assembling: C:\Users\yp0l0\AppData\Local\Temp\SASM\program.asm
C:\Users\yp0l0\AppData\Local\Temp\SASM\program.asm(30) : error A2206: missing operator in expression
LINK : fatal error LNK1181: cannot open input file "C:\Users\yp0l0\AppData\Local\Temp\SASM\program.o"
Thanks for any help!