0
; 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?

Google Z
  • 5
  • 3

1 Answers1

1

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.

rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • Thank you very much for your reply! now that i have moved end main to the end of the program, it builds successfully but trying to actually run the program just crashes. I've tried moving the procedure to different places (above main, within main, below) but no luck. Sorry I'm brand new at this! – Google Z Oct 27 '19 at 13:51
  • edit: I realized i had by accidentally added the same line of code twice which caused my issue. Thanks again!! – Google Z Oct 27 '19 at 14:09
  • @GoogleZ - in addition to the segments you have, there is also `.data?`, which is for uinitialized segement and `.stack` if you want to specify the stack size. – rcgldr Oct 27 '19 at 15:46