s0d4pop
s0d4pop

Reputation: 532

Including seperate file in original file causes original file not to run

Basically, I am using NASM to create simple .COM files to use. For one of the files(ttcb.asm), it starts out by clearing the screen. This is done by calling a routine in another file, so I used %include 'video.asm'. This includes the file as expected. When I include this file, nothing else following the %include statement in the original file(the file that included video.asm) will be executed, even if I don't call the separate routine. I also see that the code in video.asm is automatically getting executed. But when I remove the %include statement, everything runs properly. I've even tried removing everything in video.asm, but it still did not work. Then I tried making video.asm a blank file, and it worked, but that will be pointless. Then I tried moving the include statement around, but that failed as well. Is there any solution to this, or do I have to insert the subroutine directly into the original file?

ttcb.asm:

[BITS 16]


section .text

%include 'video.asm'

call screen_clear

jmp $    ;should've frozen the .COM, but it didn't, meaning it failed to execute.


section .data

welcomeMsg db 'Welcome to the TitaniumCube ©.',13,10,0,'$'

section .bss

video.asm:

;===================================
;-----------------------------------
;Clears the screen to black
;No input or output
;-----------------------------------

screen_clear:
mov ah,0Fh
int 10h
push ax
mov ah,00
mov al,00
int 10h
pop ax
mov ah,00
int 10h
ret

;-----------------------------------
;===================================

Upvotes: 0

Views: 134

Answers (1)

Jay
Jay

Reputation: 4686

For COM files, use org 100h to specify the binary base address. The .text section will be the code start address. So put all functions after the main program block ends.

Below is the code. Compile with: nasm -fbin -o ttcb.com ttcb.asm

[BITS 16]


org 100h ;set base address. must be 100h for COM files


section .text ;start of code is always start address for COM files

call screen_clear

mov ax, word welcomeMsg ;put welcomeMsg offset in register AX
;if above "org 100h" isn't specified, the above instruction would produce:
;"mov ax, 001Ch" instead of "mov ax, 011Ch"

;jmp $    ;should've frozen the .COM, but it didn't, meaning it failed to execute.
int 20h ;terminate program

%include 'video.asm'


section .data

welcomeMsg db 'Welcome to the TitaniumCube ©.',13,10,0,'$'


section .bss

PS) Under pure DOS, there's no © (copyright) character.

Upvotes: 2

Related Questions