Hi, sorry for the late response.
You are correct $ means current address and $$ means the 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 the currently executed instruction. If subtract that value from 510 you will get the offset from address of the currently executed instruction to 510th byte. So we now know how many bytes are there from address of the currently executed instruction to 510th byte. The times directive will now pad that number of bytes up to 510th byte with zeros.
Assume your codes current address $ is at
0x000f and the first address of section $$ is
$-$$ 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!!