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 function from other .asm file

Started by ghjjkl, June 18, 2014, 05:38:58 AM

Previous topic - Next topic

ghjjkl

Hi there, i'm new in asm. So, how can i call function from other .asm file? I tried just to declare .code derective in that .asm file, put function there, and then added .asm file to files must be linked. Assembling passed nice, but when i start debugging my program using afdpro, a can't recognize any code from that function - it's just called, but nothing more! Sorry for my bad eng, and thaks for attention.

Vortex

Here is a quick example for you :

include     \masm32\include\masm32rt.inc

MyFunction  PROTO :DWORD

.data

msg         db 'This is a test.',0

.code

start:

    invoke  MyFunction,ADDR msg

    invoke  ExitProcess,0

include     source2.asm

END start


source2.asm :

MyFunction PROC _text:DWORD

    invoke  szUpper,_text
    invoke  StdOut,_text
    ret

MyFunction ENDP


ghjjkl

thank you, but it seems it's wrong way for me, because i assemble dos program... when i add same code construction as you, assembler sends me errors A2034("must be in segment block") and then A1010("unmatched block nesting").

ghjjkl

wow, it seems i've found solution.
But one little question more:

seg segment
(...)
seg ends
(...)

mov ax,seg
mov ds,ax

(...)

what would be equivalent of this, if i want to send seg as parameter in function?

Gunther

Hi ghjjkl,

that's not enough information. Please post the complete code here. In general you can't overwrite a segment register without saving it.

Gunther
You have to know the facts before you can distort them.

MichaelW

Also, seg is a MASM reserved word, an operator used to return the segment of an expression.

http://msdn.microsoft.com/en-us/library/fk35xcha.aspx
Well Microsoft, here's another nice mess you've gotten us into.

Gunther

Furthermore, it doesn't make much sense to load the segment address of the callee into register DS (data segment). The qualified DOS real mode address of the callee (seggment:offset) must reside in CS:IP.

Gunther
You have to know the facts before you can distort them.

ghjjkl

Quote from: MichaelW on June 19, 2014, 01:57:14 AM
Also, seg is a MASM reserved word, an operator used to return the segment of an expression.

http://msdn.microsoft.com/en-us/library/fk35xcha.aspx
thanks, i'll remember this, i didnt check that code before post

Quote from: Gunther on June 18, 2014, 11:02:22 PM
Hi ghjjkl,

that's not enough information. Please post the complete code here. In general you can't overwrite a segment register without saving it.

Gunther
i mean, if i need implement something like this

(ONE OF .ASM FILES)

(...)

func proc near c __seg:word
mov ax, __seg
mov ds, ax

(...)

func endp

(...)

(OTHER .ASM FILE)
_seg segment

(...)

_seg ends

(...)

invoke func,???;how should i specify _seg to pass it as parameter(for operations like movsb)? Whether it should be something
               ;like "offset _seg" or simply "_seg"?

(...)

hope you will get it...

Gunther

Hi ghjjkl,

I see. You can of course pass the segment address of a procedure to another procedure. But why would you like to load that code segment address into register DS?

Gunther
You have to know the facts before you can distort them.

ghjjkl

i've edited my example...
i need just to send segment as parameter, but when i try "invoke func,_seg", assembler stops with error "error A2001: immediate operand not allowed"
That segment doesnt contains any code, but data only...

Gunther

Please give me a little bit time, to prepare an example for you.

Gunther
You have to know the facts before you can distort them.

nidud

#11
deleted

nidud

#12
deleted

Gunther

Hi ghjjkl,

you can try nidud's example and/or my example in the archive sevseg.zip. It'll assemble with MASM, jWasm or TASM.

Gunther
You have to know the facts before you can distort them.

ghjjkl

aw thanks so! Hope i'll manage to remember it   :biggrin: