0

I'm doing a boot-loader, which reads the second sector from the first head from the first cylinder of the hard drive. So to check if the program correctly reads the data, the author first writes to this sector.

; Magic number
times 510 - ($-$$) db 0
dw 0xaa55

; boot sector = sector 1 of cyl 0 of head 0 of hdd 0
; from now on = sector 2 ...
times 256 dw 0xdada ; sector 2 = 512 bytes
times 256 dw 0xface ; sector 3 = 512 bytes

So he writes two words after filling the first 512 byte. But times 256 dw 0xdada ; sector 2 = 512 bytes, doesn't make sense for me? How will write it to the second sector, there is nothing 513.. in the statement.

Henok Tesfaye
  • 8,287
  • 13
  • 47
  • 84
  • Each `dw` directive emits two bytes of data. 2 × 256 = 512. – fuz Mar 28 '19 at 14:39
  • I didn't get it @fuz. emits? – Henok Tesfaye Mar 28 '19 at 14:41
  • @fuz, if that is the case, two of the writes will overlap, but I read two of the words in my program. – Henok Tesfaye Mar 28 '19 at 14:46
  • 2
    “emits” as in “places into the binary.” If you write `dw 0xaa55`, the bytes `0x55` and `0xaa` are written into the binary. The `times` directives repeats what is after it the indicated number of times. `times 256 dw 0xdada` repeats `dw 0xdada` 256 times, writing 256 × 2 = 512 bytes. No overlap happens. – fuz Mar 28 '19 at 15:02
  • Cool, I see. What makes me vague was, the offset that times use to copy the data. Now I know that dw just puts the literal value in the raw machine code. So it doesn't need an offset. It will place two 512 bytes consecutively. – Henok Tesfaye Mar 28 '19 at 15:08

0 Answers0