I use the Bochs simulator to run a boot sector, which coded in NASM like this:
org 07c00h ;told the compiler to load the code to 0x7c00h
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ;call the string process
jmp $ ;infinite loop
DispStr:
mov ax, BootMessage
mov bp, ax ;ES:BP = string address
mov cx, 16 ;CX = length of the string
mov ax, 01301h ;AH = 13, AL = 01H
mov bx, 000ch ;(BH = 0)
mov dl, 0
int 10h ;10h interrupt
ret
BootMessage: db "Hello, OS world!" ;message printed
times 510-($-$$) db 0 ;fill the left of the 510 byte with 0
dw 0xaa55
If times 510-($-$$) db 0
if forbidden, is there any alternative way to fill the left of 510 byte area with 0?
I've tried loop command, but can not work properly.
An alternative way would be to use a preprocessor loop (%rep
):
%rep 510-($-$$)
db 0
%endrep
If your TA still isn't satisfied I'll leave it to you to dig through the NASM manual for other possible ways of achieving the same thing.