Times 510 -( $ - $$ ) db 0 means?


Later, I was reading a pdf tittled Writing a Simple Operating System from Scratch by Nick Blundell. The book basically describe how to write your own os/kernal from scratch. In that pdf I encountered the below mentioned line of assembly code which I am struggling to understand.

times 510 -( $ - $$ ) db 0

I am not familiar with assembly language. But so far I know that $ mean address of currently executing instruction and $$ means the first address of the section. Nothing else!! Any thoughts ??

You can see the whole pdf here:


Hi, sorry for the late response.

You are correct $ means current address and $$ means first address of the current section. You have to understand that the times directive only operates on numbers and the difference of address ( $-$$ ) yields a number (Offset). So $-$$ gives you the offset from start to address of currently executed instruction. If subtract that value from 510 you will get the offset from address of currently executed instruction to 510th byte. So we now know how many bytes are there from address of currently executed instruction to 510th byte. The times directive will now pad that number of bytes up to 510th byte with zeros.

For Ex:
Assume your codes current address $ is at 0x000f and first address of section $$ is 0x0000. Then $-$$ yield to 15, which implies your current instruction is at 15th byte. Now 510 - 15 will give you 495 i.e 495 bytes from current instruction will be padded with zeros by times directive.

if you dissect the binary for times 510 -( 0x000f - 0x0000 ) db 0 alone, it will exactly have 495 zeros!!


Good Job @Mr.Tesla. You have put so much effort to explain the concept. Brief and well explained.


Thanks for the responds @Mr.Tesla. Where are all these action going to take place ? RAM or Drive ?


If you read the pdf very throughly you will understand that all operation of TIMES takes place in the bootable drive.TIMES is an assembler specific commands, and as such aren’t part of x86 assembly language. Same goes for $ and $$


Thank you so much. you explained it very well.