1
votes

I am trying to use masm32 to learn about assembly. I am running Windows 8, and can compile and run sample code in the masm32 directory without issue.

I am using Quick Editor 4.0g.

However, I have the following code, straight from Kip Irvine's "Assembly Language for x86 Processors". He states that this is a bit of code that "does not depend on include files", though I am getting the sense that this may not be entirely correct.

TITLE Add and Subtract

; This program add and subtracts 32-bit Integers

.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
DumpRegs PROTO

.code
main PROC

    mov eax,10000h
    add eax,40000h
    sub eax,20000h
    call    DumpRegs

INVOKE ExitProcess,0
main ENDP
END main

When I try to build it (I go to Project and choose "Console Assemble and Link") I get the following error:

AddSubAlt.obj : error LNK2001: unresolved external symbol _ExitProcess@4
AddSubAlt.obj : error LNK2001: unresolved external symbol _DumpRegs@0
AddSubAlt.exe : fatal error LNK1120: 2 unresolved externals

I have been trying to figure this out for days. I found an answer from 2002, but it references libraries that no longer exist. I am hoping that some assembly guru angel out there can help me fix this.

Please and thank you!

2
You have to add the corresponding .lib files to linker command line for the libraries you take ExitProcess and DumpRegs from. BTW, why call ExitProcess when you can just zero eax and retn?Ruslan
or in the assembly code, you can add includelib directirves., such as | INCLUDELIB MSVCRTD | | INCLUDELIB OLDNAMES | .rcgldr
@Ruslan If you're asking me why Mr. Irvine wrote the code this way, I couldn't answer you. I also don't really understand how to do what you said.Ben I.
@rcgldr could you tell me what I need to do in baby steps? I am a rank beginner at Assembly.Ben I.

2 Answers

3
votes

First you need Irvine's library files (Kernel32.Lib, User32.Lib, Irvine32.lib, Irvine32.inc) which you can download from his site, i.e. download this file and install it: http://www.kipirvine.com/asm/examples/Irvine_7th_Edition.msi.

Now you insert some lines at the beginning of your program:

includelib C:\full\path\to\Kernel32.Lib
includelib C:\full\path\to\User32.Lib
includelib C:\full\path\to\Irvine32.lib

; include C:\full\path\to\Irvine32.inc

The include...-line is for later use and commented out for now.

1
votes

The example programs in Irvine book are supposed to be run on MS Visual studio, where you configure the library and include paths through the GUI.

If you want to assemble through command line you would have to specify the library path through command arguments. Below is an example, which worked for me.

C:\Users\QMPH64>"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\ml.exe" /I C:\Irvine\ C:\Irvine\Examples\ch03\AddSubAlt.asm /link /SUBSYSTEM:CONSOLE /LIBPATH:C:\Irvine\

Or alternatively, you can provide the individual libraries on command line as follows.

C:\Users\QMPH64>"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\ml.exe" /I C:\Irvine\  AddSub.asm /link C:\Irvine\Irvine32.lib C:\Irvine\kernel32.lib C:\Irvine\User32.Lib /SUBSYSTEM:CONSOLE