[BLUE]
Hey everyone,
I was reading a line of code from a simple bootloader,
and came across this:[/BLUE][CODE]
jmp $
times 510 - ($ - $$) db 0
[/CODE][BLUE]
This code is for NASM, but I was just curious
about two things.
First off, I *think* I know what the $'s are,
but I want to make sure at what they are, and
their uses.
Also, what are these lines of code for/do??
I ran it through Debug, but it just got me a
little confused at WHY to use these.
Any help is appreciated.
(My assembler is MASM 6.11)
Thanks;[/BLUE]
Comments
: jmp $
:
: times 510 - ($ - $$) db 0
: [/CODE]
: This code is for NASM, but I was just curious
: about two things.
As you said, this code is for NASM, you can't compile it with MASM - MASM doesn't know the times directive.
[blue]First of all - sorry for my bad english... but I'm learning...[/blue]
: : [CODE]
: : jmp $
: :
: : times 510 - ($ - $$) db 0
: : [/CODE]
: : This code is for NASM, but I was just curious
: : about two things.
:
: As you said, this code is for NASM, you can't compile it with MASM - MASM doesn't know the times directive.
: [blue]First of all - sorry for my bad english... but I'm learning...[/blue]
:
:
This little thing of TIMES stands directly in the manual of NASM.
The ($ - $$) stands for the size of your file until now.
The times 510 - ($ - $$) db 0 stands for: make the rest of the file 0's until the file is 510 bytes long. and for a boot loader the last 2 bytes, to make it a sector (512), are reserved. (somewhat like AA FF, sry but forgotten)
Greetz MI-7
[code]lbl: jmp lbl[/code]
: : : [CODE]
: : : jmp $
: : :
: : : times 510 - ($ - $$) db 0
: : : [/CODE]
: : : This code is for NASM, but I was just curious
: : : about two things.
: :
: : As you said, this code is for NASM, you can't compile it with MASM - MASM doesn't know the times directive.
: : [blue]First of all - sorry for my bad english... but I'm learning...[/blue]
: :
: :
:
: This little thing of TIMES stands directly in the manual of NASM.
: The ($ - $$) stands for the size of your file until now.
: The times 510 - ($ - $$) db 0 stands for: make the rest of the file 0's until the file is 510 bytes long. and for a boot loader the last 2 bytes, to make it a sector (512), are reserved. (somewhat like AA FF, sry but forgotten)
:
: Greetz MI-7
:
[BLUE]
Thats exactally what I was looking for! Thanks!
btw, I already know the 'times' directive wouldn't
work in MASM. So, I would use the 'dup' directive,
instead (I'm assuming their the same, right? ).
Thanks alot!
~MT2002[/BLUE]
: The ($ - $$) stands for the size of your file until now.
: The times 510 - ($ - $$) db 0 stands for: make the rest of the file 0's until the file is 510 bytes long. and for a boot loader the last 2 bytes, to make it a sector (512), are reserved. (somewhat like AA FF, sry but forgotten)
:
: Greetz MI-7
So "$" means current offset address both in MASM and NASM.
But what means "$$" in NASM? According to your description, I guess it is starting code offset, right?