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.
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
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").
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?
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
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
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
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...
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
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...
Please give me a little bit time, to prepare an example for you.
Gunther
deleted
deleted
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
aw thanks so! Hope i'll manage to remember it :biggrin:
Quote from: ghjjkl on June 19, 2014, 11:03:57 PM
aw thanks so! Hope i'll manage to remember it :biggrin:
You're welcome.
Gunther
Ahh perfect Vortex. Answered my question, my problem was a miss-located include statement.
Thanks :t
Hi drkstr,
Quote from: drkstr on September 19, 2014, 10:22:36 AM
Ahh perfect Vortex. Answered my question, my problem was a miss-located include statement.
Thanks :t
yes, that can make a lot of trouble. It's your first post after 20 months of membership. But never mind: Welcome to the forum.
Gunther