News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Back to Basics: Error Assembling a MASM32 Tutorial File!

Started by Dan-TheStarman, December 07, 2020, 04:17:46 PM

Previous topic - Next topic

Dan-TheStarman

So I decided to go through the Tutorials after installing MASM32...

Console Demos 1 - 4 (and 6-7 too), worked just fine using "Project" --> "Console Assemble & Link" in the Quick Editor.
But when I tried Demo5 (numbers.asm), even if I use a simple build.bat file instead of the Quick Editor, it keeps giving me this Assembly error either way:

error A2006: undefined symbol : crt_atol
sval(2): Macro Called From ... numbers.asm


The numbers.exe file that came with it works fine, and I checked where "crt_atol" is defined and don't see any problems there! So what's wrong??!  PLEASE TRY running this yourself using the latest MASM32 install from the website. The line of code involved in the file is:
    mov var1, sval(input("Enter a number : "))

UPDATE: Since the file itself notes that the code above was a combination of macros, I went ahead and split them, in that case the error message is still about this line of code:
    mov var1, sval(str1)

error A2006: undefined symbol : crt_atol
sval(2): Macro Called From
  C:\masm32\tutorial\console\demo5\numbers.asm(74): Main Line Code


Dan.

Vortex

Hi Dan,

atol is a function exported by msvcrt.dll  To avoid naming conflicts with some reserved Masm keywords, the msvcrt functions are prepended with the symbol crt_

You need to add the two lines below to the source code :

include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib


Part of \masm32\include\msvcrt.inc :

externdef _imp__atol:PTR c_msvcrt
crt_atol equ <_imp__atol>


jj2007

Or, a bit simpler, after line 22:

    include \masm32\macros\macros.asm       ; MASM support macros
    uselib msvcrt

Dan-TheStarman

First, Thank you for your replies!  Tested the code all different ways as suggested, works fine now!

Quote from: Vortex on December 07, 2020, 05:18:58 PM
atol is a function exported by msvcrt.dll  To avoid naming conflicts with some reserved Masm keywords, the msvcrt functions are prepended with the symbol vc_

Part of \masm32\include\msvcrt.inc :

externdef _imp__atol:PTR c_msvcrt
crt_atol equ <_imp__atol>


I just found a number of replies from Hutch about this on 16 NOV 2020 (in "Re: scanf macro and printf macro"), so I guess that's why Demo5's numbers.asm file hasn't been changed yet?  Or was this change requiring "msvcrt" much earlier?

Regarding the comment: "... the msvcrt functions are prepended with the symbol vc_," I still don't quite understand what that " vc_" has to do with the definition of sval() (and the "crt_atol" in macros.asm) and a number of capitalized "VC_"s I see in various examples. However, now that I've looked thoroughly, I see the only definition of "crt_atol" in all of the MASM32 files is in: msvcrt.inc. So it's rather obvious it must be included in the numbers.asm file.

As I wrote in my first post's later comments, most of the work I did with assembly was reversing raw hex into straight-forward assembly instructions, so many 'masm macros' are still just a bunch of crazy meaningless symbols to me. :dazzled:


Vortex

Hi Dan,

My apologies, the 32-bit version of msvcrt.inc is using the suffix crt_  The 64-bit version of the same file : vc_
I corrected this in my previous message.

\masm32\include64\msvcrt.inc :

externdef __imp_atol:PPROC
vc_atol equ <__imp_atol>


There are some Masm specific keywords like div and FABS which could collide with the sane named msvcrt functions. To avoid those confusions, Hutch prepended the functions names with crt_ and vc_

hutch--

Dan,

The general drift is while you are getting up to speed, use the system as its designed. The masm32rt.inc file has all the the correct include files, the main macro file and the matching libraries. Also don't be afraid to use the help files, they document the library procedures and the available macros you can use. Once you are up to pace you can be creative, write your own libraries, macros and architecture.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    testproc PROTO :DWORD,:DWORD,:DWORD

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    invoke testproc,1,2,3

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

testproc proc arg1:DWORD,arg2:DWORD,arg3:DWORD

    LOCAL var1  :DWORD
    LOCAL var2  :DWORD
    LOCAL var3  :DWORD

    mov eax, var1
    mov ecx, var2
    mov edx, var3

    ret

testproc endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start