Search code examples
assemblynasmpaddingmasmbootloader

MASM alternative for NASM padding to 510 bytes with times 510 - ($-$$) db 0


What will be the MASM alternative for this NASM statement?

times 510 - ($-$$) db 0

I was making a MBR bootloader. Basically this statement fills up the remaining 510 bytes on memory with 0 as a bootloader should be 512 bytes in size.


Solution

  • code segment use16
    assume cs:code
    org 7c00h
    start:
    
    ; your code
    db 510-($-start) dup(0)
    dw 0AA55h
    
    code ends
    end start
    

    Another alternative is using org to actually seek in the output file, mentioned by the NASM manual as something that works in MASM but not NASM:

    ; MASM only
            ORG 0 
    
            ; some boot sector code 
    
            ORG 510 
            DW 0xAA55