Look at it this way: if you have two files, org.asm and phant.asm:
Code: Select all
; org.asm
; the main program
%include "phant.asm"
; beginning of program
main:
mov message, si
call print
jmp $
message db "Hello, World!", 0x00
and
Code: Select all
; phant.asm
; a printing function used by org.asm
print:
push ax
mov ah, 0x0E ; set function to 'teletype mode'
.loop:
lodsb ; update byte to print by copying the value
; pointed to by SI into AL
cmp al, 0x00 ; test that it isn't zero
jz .endstring
int 0x10 ; put character in AL at next cursor position
jmp short .loop
.endstring:
pop ax
ret
; the end of phant.asm
Then, what the assembler sees is after the [tt]%include[/tt] directive is handled by the macro preprocessor is
Code: Select all
; org.asm
; the main program
; phant.asm
; a printing function used by org.asm
print:
push ax
mov ah, 0x0E ; set function to 'teletype mode'
.loop:
lodsb ; update byte to print by copying the value
; pointed to by SI into AL
cmp al, 0x00 ; test that it isn't zero
jz .endstring
int 0x10 ; put character in AL at next cursor position
jmp short .loop
.endstring:
pop ax
ret
; the end of phant.asm
; beginning of program
main:
mov message, si
call print
jmp $
message db "Hello, World!", 0x00
Clear? The [tt]%include[/tt] statement simply inserts the whole text of the included file into the the text of the file that includes it, no more and no less. The use of [tt]%include[/tt] for handling function prototypes and such is solely a convention; the [tt]%include[/tt] directive doesn't create function prototypes or affect the linking
at all. All it does is cut and paste text.
So, then, the reason you are getting the 'symbol redefined' error is because you
are defining it twice: once in functions.asm, and then
again in functions.asm, which is textually duplicated in kernel.asm at assembly time by the [tt]%include[/tt] statement. Clear?
If you are assembling the files separately, and then linking them, you don't need to [tt]%include[/tt] functions.asm in kernel.asm. Conversely, if you [tt]%include[/tt] functions.asm in kernel.asm (and you'd probably want to place it at the
end of the file if you do), then you don't need to assemble both of them and link them together.
If you assembly them separately, then you
do need to have a [global simple_print] statement in functions.asm (but not kernel.asm), so that the label gets put into function.o's linkage table for exporting; and you need an [extern simple_print] statement in kernel.asm (but not functions.asm) so that the symbol is marked as importable in kernel.o's linkage table. But if you do that, then a) don't also use [tt]%include[/tt]. lest it causes a double definition, and b) make sure that the exported label is the same as the actual label in the code.
Once again, it would help considerably if you post the actual code, whether in the message or as an attachment. HTH.