Search code examples
assemblyproceduremasmmasm32

Trying to make a simple procedure in MASM32 (LNK1120)


; Library for I/O and other purposes
include c:\asmio\asm32.inc
includelib c:\asmio\asm32.lib
includelib c:\asmio\User32.lib ; SASM files for I/O
includelib c:\asmio\Kernel32.lib ; SASM files for I/O

input proto ; 0 parameters

; -------------------------------------------------------
.const ; Section to declare and initialize constants
NULL = 0
; -------------------------------------------------------
.data ; Section to declare and initialize variables
      ; number dword ?  ;
       read byte "Enter a number between 1-12: ", NULL
; -------------------------------------------------------
.code ; The actual code begins here: Main program
main proc ; Just like C++ this is the main program
       invoke input 
 ret 0 ; need this line to return to caller
 main endp ; End of the procedure main
end main ; End of the entire program
; ------------------------------------------------------- 

input proc 
        mov   edx, OFFSET read  
        call  WriteString        
        call  ReadInt    
ret
input endp

Hey everyone!, this is my first assembly code I am trying to write.

I am attempting to create a procedure that asks the user for an input between 1-12 and then writes it to the main . I wrote the procedure below main, wrote the prototype above main, and used invoke to call the procedure within main but have run into an error.

My errors:

[08:46:41] Build started...
[08:46:42] Warning! Errors have occurred in the build:
program.o : error LNK2001: unresolved external symbol _input@0
C:\Users\yp0l0\AppData\Local\Temp\SASM\SASMprog.exe : fatal error LNK1120: 1 unresolved externals

Anyone see where I went wrong?


Solution

  • this line

            end     main
    

    needs to be the last line in the source file. Since currently it's before "input", the input function is being excluded from the assembly.