0

I'm unable to run the program below supposed to solve a quadratic equation after getting a valuable from the user. I received several syntax errors on lines I used single character identifiers, "eq", and on the end procedure line. I'm quite new to assembly and would appreciate any assistance. the errors

INCLUDE C:\Irvine\Irvine32.inc
includelib C:\masm32\lib\User32
includelib C:\masm32\lib\Kernel32.lib
includelib C:\Irvine\Irvine32.lib

.data
two dword 2 ; store two
three dword 3 ; store three
c dword 1 ; store 1
n dword  ? ; n variable
answer dword  ? ; answer variable
a1 dword ? ; store 2n^2
a2 dword ? ; store 3n
pr BYTE 'Enter n:',0dh, 0ah,0     ; n prompt
eq BYTE 'ans= ',0 ; ans

.code

n2n PROC ; 2*n*n
mov eax, two
mov ecx, n
mul ecx
mov ecx,n
mul ecx
mov a1,eax
ret
n2n ENDP

n3 PROC   ; 3n
mov eax, three
mov ecx, n
mul ecx
mov a2,eax
ret
3n ENDP

main PROC
mov edx, offset pr
call WriteString ; Ask user for n

call readInt
mov  n, eax ; Store user input in n

call n2n ; call procedure n2n
call 3n ; call procedure n3

mov ebx, a1
add ebx, a2
add ebx, c
mov answer, ebx ; store result in answer

mov edx, offset eq
call WriteString

mov eax, answer
call WriteDec
call WaitMsg

 exit
main ENDP
END main
  • side note: n2n is way overcomplicated. just `mov eax, n` / `imul eax,eax` / `add eax,eax` (or shift left by 2). Or just inline it, instead of storing `n` to memory first. You definitely don't need to load small integer constants like `2` or `3` from memory; never do that. `n3` could be `imul eax, n, 3` / `ret`. (Unlike most other instructions, `imul` with an immediate also takes separate dst and src operands.) – Peter Cordes Mar 09 '22 at 04:35
  • But anyway, some of those names might be reserved in MASM; try with longer names like `foo_c` or `my_c` or whatever just to make sure they're not something the language already defines. See [Why is the variable name "name" not allowed in assembly 8086?](https://stackoverflow.com/q/52955216) for example. – Peter Cordes Mar 09 '22 at 04:36

0 Answers0