NASM Forum > Example Code
Hello World
Structure:
.zeroTerminated:
--- Code: ---times 512-($-$$) db 0
jmp start
print:
pusha
.printloop:
mov al, [si]
cmp al, 0
jne .printchar
popa
ret
.printchar:
mov ah, 0x0e
int 0x10
add si, 1
jmp .printloop
ret
string: db "Hello World.", 0
start:
mov si, string
call print
--- End code ---
debs3759:
--- Quote from: Structure on December 11, 2019, 04:03:35 PM ---.zeroTerminated:
--- Code: ---times 512-($-$$) db 0
jmp start
print:
pusha
.printloop:
mov al, [si]
cmp al, 0
jne .printchar
popa
ret
.printchar:
mov ah, 0x0e
int 0x10
add si, 1
jmp .printloop
ret
string: db "Hello World.", 0
start:
mov si, string
call print
--- End code ---
--- End quote ---
In your code, if that is the entire code, $ = $$ (both are at the start of your code). So
times 512-($-$$) db 0
inserts 512 0 bytes at the start of the code. What is that for?
Structure:
The first 512 kb are reserved for the boot sector:
https://en.wikipedia.org/wiki/Boot_sector
or a file header, etc...
debs3759:
I did wonder if this was related to a boot sector, but it wasn't obvious from your code. My FAT12 boot sector code is lower down in this forum :)
T145:
You don't need any of that bootcode, since you're not making anything to boot into, like a virtual floppy disk. As you know, in 16 bit land we just start executing from the top, so you can always just use the following macro to print your string:
--- Code: ---%macro puts 1
pushaw
mov si, %1
mov ah, 0Eh ; INT 10h doesn't trash ah or bx
mov bx, 7 ; video mode support
%%read:
lodsb
test al, al ; check for null-terminating character (0)
jz %%done
int 10h ; print character in al
jmp %%read
%%done:
popaw
%endmacro
--- End code ---
Then just `puts string` and either `ret` or `jmp $` to avoid running into the data section.
Navigation
[0] Message Index
[#] Next page
Go to full version