With code like so:

[BITS 16]       ; 16 bit code generation
[ORG 0x7C00]    ; Origin of the program. (Start position)

; Main program
main:       ; Put a label defining the start of the main program

 call PutChar   ; Run the procedure

jmp $       ; Put the program into a never ending loop

; Everything here is out of the main program
; Procedures

PutChar:        ; Label to call procedure
 mov ah,0x0E        ; Put char function number (Teletype)
 mov bh,0x00        ; Page number (Ignore for now)
 mov bl,0x07        ; Normal attribute
 mov al,65      ; ASCII character code
 int 0x10       ; Run interrupt
 ret            ; Return to main program

times 510-($-$$) db 0   ; Zero's for the rest of the sector
dw 0xAA55       ; Bootloader signature

The first thing I thought with times 510-($-$$) db 0 was that it was going to wipe out all the written instructions... but apparently not so since I trust this is valid code. Why is this not so? I figured that, well, maybe the data declarations get evaluated first during assembly and then the instructions after, but then I thought of one and two pass assemblers and that my thinking could be false with one pass assemblers.

Why is this code valid when I figure times 510-($-$$) db 0 would clean out the whole file before it with zero?

4 Years
Discussion Span
Last Post by asrockw7

I figured it out... my bad. I missed the fact that $ increases as you put more lines...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.