News:

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

Question about undefined symbol while compiling

Started by marcus, March 04, 2010, 04:06:46 PM

Previous topic - Next topic

marcus

hi everyone,

I have a question about something I do not understand while trying to compile this very simple code
(this program does nothing, this is only to reproduce a compilation error).

.model small
.386
.stack 100
.data
   dd 3bfcedcbh
   dd e92eada4h
.code

START:
END

So when I am compiling this, I am getting at line 6:  error A2006: undefined symbol: e92eada4h , while
at line 5 this is Ok.

The only difference between the two dd I can see is that one is over the maximum value (line 6) of a signed DWORD while the other
one is not line(5).

So, how could I use a dd statement with this value without having the compilation error.

thanks for your time,
Marc





dedndave

when defining hexidecimal values that begin with letters (A-F or a-f), you have to precede them with a 0
otherwise, the assembler thinks it is a label of some sort
also, labels are not allowed to start with a number (0-9)

   dd 0e92eada4h

qWord

Also you have not specific the entry point of program:
START:
...
END START


FPU in a trice: SmplMath
It's that simple!

marcus

Quote from: dedndave on March 04, 2010, 04:16:39 PM
when defining hexidecimal values that begin with letters (A-F or a-f), you have to precede them with a 0
otherwise, the assembler thinks it is a label of some sort
also, labels are not allowed to start with a number (0-9)

   dd 0e92eada4h


hi dedndave,
thanks, now I feel less stupid :)


marcus

Quote from: qWord on March 04, 2010, 04:19:27 PM
Also you have not specific the entry point of program:
START:
...
END START




Hi qWord,
Thanks! Very good... that fixes the second problem with the linker for "unresolved external symbol _mainCRTStartup"
while it looks like that to avoid a warning I have,I had to do
_START:
END _START

hutch--

marcus,

Unless you are building for 16 bit real mode, your directives are wrong. The only memory model for win32 is .model FLAT, STDCALL and you do not set the stack in win32 in the asm code, you set it in the linker if you need different to default.

If its 16 bit code, you must use a 16 bit linker that is different to the 32 bit version.

Let us know what you are building with and for what target OS.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

marcus

Quote from: hutch-- on March 05, 2010, 06:07:45 AM
marcus,

Unless you are building for 16 bit real mode, your directives are wrong. The only memory model for win32 is .model FLAT, STDCALL and you do not set the stack in win32 in the asm code, you set it in the linker if you need different to default.

If its 16 bit code, you must use a 16 bit linker that is different to the 32 bit version.

Let us know what you are building with and for what target OS.

Hi Hutch,
Thanks for this information.
While I am experienced in programming, and can understand ASM code, I am new in programming it ( I am doing this just for fun :) ), so every advice is nice ;)
To answer your question, the target OS is win32. What I am building is some code I got from a magazine which analyze a backdoor program in ASM (wrote in NASM),  so to see better the inner working
I wanted to build it and see everything which is happening under the debugger.


dedndave

it is a 16-bit program
you will need a 16-bit linker
if you have no linker errors, you must have figured that out   :bg

marcus

Quote from: dedndave on March 05, 2010, 11:02:37 AM
it is a 16-bit program
you will need a 16-bit linker
if you have no linker errors, you must have figured that out   :bg
No linker error ...but this is linked with 32bits libraries...
but the program is crashing anyway...I am wondering if those code found in magazines are
really working...

BlackVortex

Those assembler directives are for 16bit programs. Delete that source and try to assemble+link one of the tutorials and check if it works correctly.

THEN start messing around  :lol

Also, are you assembling and testing that empty program in your first post ? If yes, then of course it's gonna crash.

marcus

Quote from: BlackVortex on March 05, 2010, 04:43:10 PM
Those assembler directives are for 16bit programs. Delete that source and try to assemble+link one of the tutorials and check if it works correctly.

THEN start messing around  :lol

Also, are you assembling and testing that empty program in your first post ? If yes, then of course it's gonna crash.

LOL :)

I already tried some tutorials and they works properly.

And... I am not assembling this empty program :) ...that was just to show the compile error I had.
The program I am assembling is a 200 lines of code (that I didn't wrote). For the moment I am just trying to
understand why it does not start with the usual prologue...

push ebp
mov ebp,esp

etc....


but like this:

    call basePtr
LDataSegment:
     ; here some memory initialization which should remain in the .code part
     ; for later use...
basePtr:
    pop ebx
    push esp
    mov ebp,esp
    mov [ebp],ebx
etc...




   









BlackVortex

I think he doesn't intend to return to that first call, so it does an extra pop to keep the stack more balanced.

Anyway, in assembly you can do whatever the heck you think is better.

For example, he is coding the prologue manually, instead of declaring a procedure and then using invoke (instead of a simple call). Unless it's source code for NASM, which you mentioned, then NASM sucks.

dedndave

you have a case of mix and match, then
you need to remove those model, casemap, and stack directives as Hutch suggested
those are for 16-bit code
for 32-bit code, it should look more like this...

        .486
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

notice the absence of a .STACK directive

marcus

Quote from: BlackVortex on March 05, 2010, 05:33:14 PM
I think he doesn't intend to return to that first call, so it does an extra pop to keep the stack more balanced.

Anyway, in assembly you can do whatever the heck you think is better.

For example, he is coding the prologue manually, instead of declaring a procedure and then using invoke (instead of a simple call). Unless it's source code for NASM, which you mentioned, then NASM sucks.

Yes, the source code was for NASM. I only modified it to be able to compile it for MASM, but there is probably something missing.

marcus

Quote from: dedndave on March 05, 2010, 06:05:23 PM
you have a case of mix and match, then
you need to remove those model, casemap, and stack directives as Hutch suggested
those are for 16-bit code
for 32-bit code, it should look more like this...

        .486
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

notice the absence of a .STACK directive

I already removed the .STACK and change the .MODEL ...the only missing one was CASEMAP:NONE ...
If I use the FLAT model, this line does not compile ( error A2108: use of register assumed to ERROR) ...
   mov eax,fs:[ecx]
but if I use the LARGE model, it does.

Now, the interesting thing (thanks for pointing to me that the .486 directive was before .model) is that if I do

.486
.model large,stdcall
option casemap:none
.data
.code

I can run the program under debug and it does not crash .... BUT if I do (note the .486 under .model this time):

.model large,stdcall
option casemap:none
.486
.data
.code
it crash immediately...
Anybody knows why?