News:

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

Main Menu

Calling an external function

Started by sys64738, October 13, 2013, 06:49:58 AM

Previous topic - Next topic

sys64738

I'm trying to implement procedures in separate object modules. Can somebody show me an example how I should declare this? Or a sample project so I can take a look at it?

Thanks!

jj2007

Assemble this, and keep the obj file:
include \masm32\include\masm32rt.inc

.code
MBox proc mtext
   invoke MessageBox, 0, mtext, chr$("Title"), MB_OK
   ret
MBox endp
end


Then assemble this:
include \masm32\include\masm32rt.inc

MBox PROTO :DWORD

.code
start:   invoke MBox, chr$("This is the text")
   exit

end start


And add MBox.obj to the linker's commandline.

RuiLoureiro

Quote from: sys64738 on October 13, 2013, 06:49:58 AM
I'm trying to implement procedures in separate object modules. Can somebody show me an example how I should declare this? Or a sample project so I can take a look at it?

Thanks!

Hi sys64738

«I'm trying to implement procedures in separate object modules...»

I dont know exactly what you want to do
but we may write
data and procedures in File1.asm
and
data and procedures in File2.asm

etc.
and, in main file,
we write something like this:
----------------------------------------
...
include     File1.asm
include     File2.asm
...

.data
???
.code
...
start:

???
end start
----------------------------------------
Another way is to put File1, File2, etc.
into a library.

Then we use
           includelib  MyLib.lib
-----------------------------------------           

sys64738

Quote from: jj2007 on October 13, 2013, 07:18:54 AM
Assemble this, and keep the obj file:
include \masm32\include\masm32rt.inc

.code
MBox proc mtext
   invoke MessageBox, 0, mtext, chr$("Title"), MB_OK
   ret
MBox endp
end


Then assemble this:
include \masm32\include\masm32rt.inc

MBox PROTO :DWORD

.code
start:   invoke MBox, chr$("This is the text")
   exit

end start


And add MBox.obj to the linker's commandline.

Thanks! I did this, but when I link it, I get a linker error
Quote
Main.obj : error LNK2001: unresolved external symbol _memset@0

It seems that the name got mangled, but why? How can I disable this?


Quote from: RuiLoureiro on October 13, 2013, 07:40:29 AM
I dont know exactly what you want to do
but we may write
data and procedures in File1.asm
and
data and procedures in File2.asm

That's exactly what I wanted to do, but I don't want to include the asm file into another.

sys64738

Just noticed. Apparently the name did NOT get mangled, instead the IDE doesn't assemble the second module into an obj file. :( I'm using WinASM because EasyCode was not so clear to me, it seem to take to much control away.

sys64738

I'm using now Visual Studio 2008 as my IDE and thus got rid of the linking problem. With your sample how to define a function and call it, it works now. Thanks! :)

qWord

when searching for "module" or "modules" in the Help of WinASM, the first entry in the result list is the topic "Project", which explains how to setup a module. I'm sure the help file of EC also contains such information.
:t
MREAL macros - when you need floating point arithmetic while assembling!

RuiLoureiro

Quote from: RuiLoureiro on October 13, 2013, 07:40:29 AM
Quote from: sys64738 on October 13, 2013, 06:49:58 AM
I'm trying to implement procedures in separate object modules. Can somebody show me an example how I should declare this? Or a sample project so I can take a look at it?

Thanks!

Hi sys64738

«I'm trying to implement procedures in separate object modules...»

I dont know exactly what you want to do
but we may write
data and procedures in File1.asm
and
data and procedures in File2.asm

etc.
and, in main file,
we write something like this:
----------------------------------------
...
include     File1.asm
include     File2.asm
...

.data
???
.code
...
start:

???
end start
----------------------------------------
Another way is to put File1, File2, etc.
into a library.

Then we use
           includelib  MyLib.lib
-----------------------------------------         
Hello all,
              Is there any difference btw

method 1: include File1.asm and File2.asm
                 into main file assemble & link
and

method 2: assemble all
                 Link main file with File1.obj and File2.obj ?

dedndave

if you link individual OBJ files, the linker has a set of rules that determine the order things are put into the EXE file
if you put them in an ASM file, you control the order
not much of a difference, usually - sometimes it might be an advantage to help caching

it's really more a question of house-keeping
i can see where you may want to have a set of functions in an OBJ

it seems more tidy to use a little static LIB, though
that's probably a good solution for the original poster, too   :t
create a LIB - create in INC with the prototypes - and add it like any other LIB

dedndave


RuiLoureiro

Quote from: dedndave on October 15, 2013, 03:15:54 AM
a little static lib example...

Hi Dave,
         Ok, i like to use a library  ;)
         and i use my library the same way
         you do.
         I like .glb instead of .inc,
         something like this:


FileX.asm is this:
*************

...

;----------------------------------------------
        include FileX.glb
        include FileY.glb
        include FileZ.glb       
;----------------------------------------------       
.data
_varX1          db ?
_varX2          dd ?


.code
ProcX1         proc   var1:DWORD, var2:DWORD
               ...               
               ret
ProcX1         endp

ProcX2         proc
               ...               
               ret
ProcX2         endp

...

ProcXN         proc   var1:DWORD
               ...               
               ret
ProcXN         endp
; ------------------------------------------
end

FileX.glb is this:
************
EXTERNDEF _varX1:BYTE
EXTERNDEF _varX2:DWORD
;-------------------------------------
ProcX1         proto    :DWORD,:DWORD
ProcX2         proto
ProcXN         proto    :DWORD



FileY.asm is this:
*************

...

;----------------------------------------------
        include FileX.glb
        include FileY.glb
        include FileZ.glb       
;----------------------------------------------       
.data
_varY1          db ?
_varY2          dd ?

.code
ProcY1         proc   var1:DWORD, var2:DWORD
               ...               
               ret
ProcY1         endp

ProcY2         proc
               ...
               call    ProcX2
               ...               
               ret
ProcY2         endp

...

ProcYN         proc   var1:DWORD
               ...               
               ret
ProcYN         endp
; ------------------------------------------
end

FileY.glb is this:
************
EXTERNDEF _varY1:BYTE
EXTERNDEF _varY2:DWORD
;-------------------------------------
ProcY1         proto    :DWORD,:DWORD
ProcY2         proto
ProcYN         proto    :DWORD


FileZ.asm is this:
*************

...

;----------------------------------------------
        include FileX.glb
        include FileZ.glb       
;----------------------------------------------       
.data
_varZ1          db ?
_varZ2          dd ?


.code
ProcZ1         proc   var1:DWORD
               ...               
               ret
ProcZ1         endp

ProcZ2         proc
               ...               
               ret
ProcZ2         endp

...

ProcZN         proc   var1:DWORD
               ...               
               ret
ProcZN         endp
; ------------------------------------------
end

FileY.glb is this:
******************
EXTERNDEF _varZ1:BYTE
EXTERNDEF _varZ2:DWORD
;-------------------------------------
ProcZ1         proto    :DWORD
ProcZ2         proto
ProcZN         proto    :DWORD


dedndave

i don't think the fle extension matters - so long as the one in INCLUDE matches the file   :P

RuiLoureiro

#12
Quote from: dedndave on October 15, 2013, 07:52:23 AM
i don't think the fle extension matters - so long as the one in INCLUDE matches the file   :P
Yes Dave  ;)
I do this because i use .inc for other cases.
.glb means global.

sys64738

Quote from: dedndave on October 15, 2013, 02:59:37 AM
it seems more tidy to use a little static LIB, though
that's probably a good solution for the original poster, too   :t

Yes, I know, that a lib is the better approch, but for now I only have two or three functions in there :p and I seem to have troubles enough with the masm syntax, so I don't want to add this on top. :)