I am using visual c++ express compiler to compile asm32:
; Example assembly language program -- adds 158 to number in memory
; Author: R. Detmer
; Date: 1/2008
.586
.MODEL FLAT
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
number DWORD -105
sum DWORD ?
.CODE ; start of main program code
main PROC
mov eax, number ; first number to EAX
add eax, 158 ; add 158
mov sum, eax ; sum to memory
mov eax, 0 ; exit with return code 0
ret
main ENDP
END ; end of source code
the above gives me a linking error, whereas this:
..
.CODE ; start of main program code
main:nop
mov eax, number ; first number to EAX
add eax, 158 ; add 158
mov sum, eax ; sum to memory
mov eax, 0 ; exit with return code 0
ret
end main ; end of source code
..
works greatly!
the only difference is the main:nop vs main proc
what is the difference between these two and why is one closed by end main and the other is main endp main ?
here’s the error i get:
1>------ Build started: Project: asm1, Configuration: Release Win32 ------
1> Assembling [Inputs]...
1>LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
1>C:\Users\...\Downloads\asm1\Release\asm1.exe : fatal error LNK1120: 1 unresolved externals
It doesn’t have anything to do with the PROC directive. Your original code is missing the ‘main’ operand on the END directive. Which specifies the entrypoint for the program. Without one, the linker is going to try to find the default entrypoint for an executable, _WinMainCRTStartup. And that fails because you don’t have that and don’t link the CRT.
Fix: