News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help with Visual Studio and masm

Started by dontoo, March 23, 2010, 09:47:06 PM

Previous topic - Next topic

dontoo

I am learning masm from book "Introduction to 80 x 86 Assembly Language and Computer Architecture" and want to create project in VS 2008 Pro. I have three files, main.asm, io.h and io.obj. I can successfully complie and run program from Visual Studio Command prompt with these comands:
ml /c /coff main.asm
link /subsystem:console /entry:start /out:main.exe main.obj io.obj kernel32.lib
But when I create project in VS I got linker errors in io.h file:
error LNK2001: unresolved external symbol atoiproc
error LNK2001: unresolved external symbol dtoaproc
error LNK2001: unresolved external symbol atodproc........
These are the steps that I made.
1. Create empty VC++ project
2. Add new .asm file and .h file
3. Copy io.obj file in the debug folder
4. Linker -> system -> Console (/SUBSYSTEM:CONSOLE)
5. Custom build rules: masm
; Example assembly language program -- adds two numbers
; Author:  R. Detmer
; Date:    revised 7/97; revised by jaj 11/11/09

        .386
        .model flat

ExitProcess Proto Near32 StdCall, dwExitCode:DWord

Include io.h       

cr      equ     0dh   
Lf      equ     0ah   

        .stack 4096     

        .data
number1 dword   ?
number2 dword   ?
sum     dword   ?
prompt1 byte    "Enter first number:  ", 0
prompt2 byte    "Enter second number:  ", 0
string  byte    40 Dup (?)
sumis   byte    cr, Lf, "The sum is "
sumch   byte    11 Dup (?)
        byte    cr, Lf, 0

        .code
_start:
        output  prompt1         ; prompt for first number
        input   string, 40      ; read ASCII characters
        atod    string          ; convert to integer
        mov     number1, eax    ; store in memory

        output  prompt2         ; repeat for second number
        input   string, 40
        atod    string
        mov     number2, eax
       
        mov     eax, number1    ; sum = number1 + number2
        add     eax, number2   
        mov     sum, eax       
        output  sumis           ; output message
        dtoa    sumch, eax      ; convert to ASCII characters
        output  sumch

        invoke  ExitProcess, 0 

Public _start                   ; make entry point public

       end                      ; end of source code



io.h
; IO.H -- header file for I/O macros
; 32-bit version for flat memory model
; R. Detmer   last revised 8/2000
.NOLIST     ; turn off listing
.386

            EXTRN  itoaproc:near32, atoiproc:near32
            EXTRN  dtoaproc:near32, atodproc:near32
            EXTRN  inproc:near32, outproc:near32

itoa        MACRO  dest,source,xtra    ;; convert integer to ASCII string

            IFB    <source>
            .ERR <missing operand(s) in ITOA>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in ITOA>
            EXITM
            ENDIF

            push   ebx                  ;; save EBX
            mov    bx, source
            push   bx                   ;; source parameter
            lea    ebx,dest             ;; destination address
            push   ebx                  ;; destination parameter
            call   itoaproc             ;; call itoaproc(source,dest)
            pop    ebx                  ;; restore EBX
            ENDM

atoi        MACRO  source,xtra          ;; convert ASCII string to integer in AX
                                        ;; offset of terminating character in ESI

            IFB    <source>
            .ERR <missing operand in ATOI>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in ATOI>
            EXITM
            ENDIF

            push   ebx                 ;; save EBX
            lea    ebx,source          ;; source address to EBX
            push   ebx                 ;; source parameter on stack
            call   atoiproc            ;; call atoiproc(source)
            pop    ebx                 ;; parameter removed by ret
            ENDM

dtoa        MACRO  dest,source,xtra    ;; convert double to ASCII string

            IFB    <source>
            .ERR <missing operand(s) in DTOA>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in DTOA>
            EXITM
            ENDIF

            push   ebx                 ;; save EBX
            mov    ebx, source
            push   ebx                 ;; source parameter
            lea    ebx,dest            ;; destination address
            push   ebx                 ;; destination parameter
            call   dtoaproc            ;; call dtoaproc(source,dest)
            pop    ebx                 ;; restore EBX
            ENDM

atod        MACRO  source,xtra         ;; convert ASCII string to integer in EAX
                                       ;; offset of terminating character in ESI

            IFB    <source>
            .ERR <missing operand in ATOD>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in ATOD>
            EXITM
            ENDIF

            lea    eax,source          ;; source address to EAX
            push   eax                 ;; source parameter on stack
            call   atodproc            ;; call atodproc(source)
                                       ;; parameter removed by ret
            ENDM

output      MACRO  string,xtra         ;; display string

            IFB    <string>
            .ERR <missing operand in OUTPUT>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in OUTPUT>
            EXITM
            ENDIF

            push   eax                 ;; save EAX
            lea    eax,string          ;; string address
            push   eax                 ;; string parameter on stack
            call   outproc             ;; call outproc(string)
            pop    eax                 ;; restore EAX
            ENDM

input       MACRO  dest,length,xtra    ;; read string from keyboard

            IFB    <length>
            .ERR <missing operand(s) in INPUT>
            EXITM
            ENDIF

            IFNB   <xtra>
            .ERR <extra operand(s) in INPUT>
            EXITM
            ENDIF

            push   ebx                 ;; save EBX
            lea    ebx,dest            ;; destination address
            push   ebx                 ;; dest parameter on stack
            mov    ebx,length          ;; length of buffer
            push   ebx                 ;; length parameter on stack
            call   inproc              ;; call inproc(dest,length)
            pop    ebx                 ;; restore EBX
            ENDM


.NOLISTMACRO ; suppress macro expansion listings
.LIST        ; begin listing




hutch--

Without addressing all of your questions, first things is you need include files that are written in MASM notation where .H files are usually in C/C++ notation. I would be inclined to download the MASM32 project as it is designed to build current 32 bit binaries and it has the bulk of MASM prototypes for the API function range. Setting up VC is not really my specialty but if you use the correct include file and libraries then MASM code will build in VC.

From memory the Detmer book is a bit out of date although it may be useful to get the basic concepts but I would suggest that you download the Intel manuals as reference material and have a good look around the masm code that is available. This stuff is reasonably straight forward if you start with the right basic templates and use libraries and include files that match properly.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

GregL

Hutch,

The Richard Detmer book "Introduction to 80 x 86 Assembly Language and Computer Architecture" was just updated this year (2010). The .h files for his book are in MASM format.


dontoo,

It looks like the linker just can't find the io.obj file.  Use the full path if needed.

Add it to Linker -> Input -> Additional Dependencies

(I am using VS 2010 so it might not be exactly the same menu steps)


dontoo

I add additional dependence to io.obj file but instead 7 errors I get two errors
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\don\Documents\Visual Studio 2008\Projects\masm\Debug\masm.exe : fatal error LNK1120: 1 unresolved externals

Files main.asm, io.h, io.obj work when I compile them from command prompt so I must configure them form VS too.

hutch--

The first error "1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup" usually means you don't have an entry point to the app.

Try a "start" label and at the end of the code a line with "end start".

You put "start:" at the beginning of the code section, not in the data section.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dontoo

I lost these old errors but now have one new error:
A tool returned an error code from "Assembling...

dontoo

when I compile code from command line it works. I guess I need to configure project in VS, but don't know how.

dontoo

Guess I will need to compile book examples from command line but I have one question. I need to use VS debugger but when I start debugger with this command:
devenv myprogram.exe /debugexe
I get message "Binary was not built with debug information"
I compile myprogram with this commands:
ml /c /coff myprogram.asm
link /subsystem:console /entry:start /out:myprogram.exe myprogram.obj io.obj kernel32.lib
These are the list of MS MASM commands http://msdn.microsoft.com/en-us/library/s0ksfwcf(VS.100).aspx
I cant find any debugging commands.
How to generate debugging information when I compile from command line? What command to use?

clive

It could be a random act of randomness. Those happen a lot as well.

redskull

Also, link with the /DEBUG option (and /PDB to specify a different output filename)

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

GregL

dontoo,

It will work in Visual Studio, you just need to learn how to set it up correctly. Re-read instructions in the book. If you can't figure it out then you can just use the command-line for now, there's nothing wrong with that.