Hello everyone. I am currently learning how to program in assembly language.

I am currently using TASM for my school projects and i would like to know how can i split my source code into various files which will be much easier for me to maintain. For example, i will have a main file which will contain the main calls of other procedures and minor calculations. Then i will have another file which will contain all my procedures.

Pretty much like this simple program:

;main source file:
include
.386
assume cs:main, ds:main
main segment
org 100h
start:
extrn function: near
call function
int 20h
main ends
end start

;procedures source file
main segment
public function
function proc
mov ax, 0b800h
mov es, ax
mov byte ptr es:[0], 'A'
ret
function endp
main ends
end

Then i have to assemble both files into two object files and link them together.

tasm32 file1
tasm32 file2
tlink /t file1 file2

Or that is as far i figured out. I don't know what i am doing wrong. I know i have to use the key words "extrn", "public" and maybe (not sure) "include". I get a linking error saying invalid point of entry address.
Posted on 2007-11-16 21:00:11 by banzemanga
You have to let the linker know the program entry-point. This is a two step process. First, the entry procedure must be GLOBAL. Two, most linkers have a command-line switch/option to specify that entry name.

There are some quirks to watch out for, most notably that some linkers expect a leading underscore for functions. This may be just the problem, in that you need to define _main instead of main.

I haven't used TLINK in such a long time, and my suggestions may be way off since I can see "main segment", but they are worth a shot as they hold true in standard cases.
Posted on 2007-11-16 21:07:52 by SpooK
It seems that TASM is able to handle the start without the underscore " _ ". Well, i'll put it anyway.

Can you give me example of how you do it with your linker and assembler?

Thanks
Posted on 2007-11-17 17:31:47 by banzemanga

It seems that TASM is able to handle the start without the underscore " _ ". Well, i'll put it anyway.

Can you give me example of how you do it with your linker and assembler?

Thanks


Here is a example that is compatible with most situations, using NASM and POLINK.


;Assemble: nasm.exe -f win32 file.asm -o file.obj
;Link: polink.exe /SUBSYSTEM:CONSOLE /ENTRY:_main file.obj kernel32.lib

GLOBAL _main


_main:
;do some cool program stuff...
xor eax,eax
ret
Posted on 2007-11-17 18:18:51 by SpooK
IIRC, the second (and every additional) asm file must NOT have the trailing "end" directive. The end directive marks the entrypoint.

(Actually, it should be named "start", not "end", because this way it's very confusing.)

So just delete that last 'end' in the 'functions' file. and it should build.
Posted on 2007-11-18 09:40:12 by ti_mo_n
@ti_mo_n
No, if i delete end. It shows an assembling error saying that unexpected end of file encountered.

I am still unable to solve the problem. I look around a little bit more.

Thanks.
Posted on 2007-11-18 19:43:53 by banzemanga
I do not recall TASM having any such limitation when producing object modules.
Posted on 2007-11-18 20:01:12 by Rockoon
I've just checked the manual.
tlink /t file1 file2

the parameters should be:
tlink obj1+obj2 finalexe

(finalexe is optional)
The order you specify the OBJs in is important: objects will be placed within the exe in exactly this order.

Make sure that only 1 .asm ends with "end <label>", and yes - the rest must end with just "end".
Posted on 2007-11-18 21:44:07 by ti_mo_n
Ok... it took me time and some research to find out the way of doing it and why it did not work.

According to my professor, the reason it did not work was because i was missing some directives.
It did work after i added the directive "model tiny" in any of the separate source files.
I read in a TASM manual stating that "model tiny" = assuming cs, ds and ss main segment
but it seems that there is another directive inside "model tiny" other than the segment assumptions
because even though i did the correct assumptions, the program did not work.

Here are the source code.

main.asm
.model tiny

assume cs:main, ds:main, ss:main
main segment
org 100h

start:

extrn function:near ;indicates the procedure is on another source file
call function

int 20h

main ends
end start


p.asm
assume cs:main, ds:main, ss:main
main segment
org 1h ;needed at least one byte otherwise procedure is damaged

public function ;makes the procedure usable in other source
function proc near
mov ax, 0003h
int 10h
mov ax, 0b800h
mov es, ax
sub bx, bx
mov ax, 0f041h
mov es:, ax
retn
function endp

main ends
end


to make the object files
tasm32 main
tasm32 p


to link the files
tlink /t main p


@ti_mo_n
the '/t' argument is to make a .com file and without the '+' argument does not seem to
make difference in the linker i use it separates object files and other kind of files by comas
but i really apreciate your will to help and even going as far as checking the manual.
tlink  objfiles, exefiles, mapfiles, libfiles, etc

Posted on 2007-12-31 21:35:15 by banzemanga