I am trying to make a program that will compute and print the factorial of an integer read in from a user. The current code I have is not working, I am getting lots of errors at lines saying there is a syntax error in instruction but I don’t understand what is wrong with it.
.CODE
_MainProc PROC
; Print the prompt
output prompt
; Read the number
input num, 4
; Convert input to integer
atod num
mov ecx, eax
; Check if the number is negative
cmp ecx, 0
jl negative_number
; Check if the number is 0
cmp ecx, 0
je zero_number
; Compute factorial
mov eax, 1 ; EAX will hold the result
mov ebx, 1 ; EBX will be the counter
factorial_loop:
cmp ebx, ecx ; Compare counter with input number
jg factorial_done ; If counter > input, we are done
imul eax, ebx ; Multiply EAX by counter
inc ebx ; Increment counter
jmp factorial_loop ; Repeat the loop
factorial_done:
; Convert result to string
dtoa result, eax ; Convert the integer result to a string
; Print the result message
output result_msg
; Print the factorial result
output result
; Exit program
exit
negative_number:
; Print the negative number message
output neg_msg
jmp exit_program ; Exit program
zero_number:
; Print the result message
output result_msg
; Print '1' for factorial of 0
output one
jmp exit_program ; Exit program