You are not logged in.
Hello,
I've been programming with nasm for some time. Usually when I wanted to use more than one file, I would simply "%include" it......
Recently I tried using ld to link multiple assembly files together... After a while, I finally got it to mostly work how I wanted.
Now I am trying to write up a boot sector using multiple files. Now by the requirements of boot sectors, the sector must be 512 bytes and the last 2 bytes must be 0x55 and 0xAA (or 0xAA55).
Usually in assembly I would simply do something like this at the end of the code:
times 510-($-$$) db 0 ; Fill up the file with zeros
dw 0xAA55 ; Boot sector identifier
However if I have this code + additional assembly code, the additional assembly code gets padded on, thus the size becomes more than 512 bytes.
I have concluded that ld cannot somehow attach the information into 512 bytes... or otherwise it would be difficult to get it to do so.
So I have modified my strategy. Instead of padding on a lot of spaces and the 0xAA55 in assembly code, it seems to be more efficient to first compile and link everything.. and only afterwards, pad on the extra bytes and add in the 0xAA55 into the file raw binary.
I have succeeded in making the file raw binary.. currently it's about 90 bytes (plenty of space before I hit 512)... Does anybody know how to pad on the extra bytes and add on byte 0x55 and byte 0xAA at the end to make the file final size 512?
A command line function to use would be much appreciated.
Thank you,
LiteHacker
Offline
If you first make one file consisting of
0000000...AA55 (template)
then you can use dd:
dd if=bootsector of=template conv=notrunc
Offline
Well, it worked. Thank you Procyon.
Interesting... I didn't know "dd" left all other data in "of" the same if it wasn't overwritten.
Well, we learn something new every day.
If anybody thinks they know a better way not requiring writing an extra file, feel free to post. Otherwise, this method works great.
LiteHacker
Offline
Alternatively, if you've got a file (eg, "trailer") containing AA 55 and no newline, you can just use cat with the append redirection:
cat trailer >> file
Offline
Okay, new question:
I currently have an image of one sector. I would like to append another file to it. (This other file represents one or more other sectors)... Both of these files are binary files. From what I understand, "cat" seems to only work with regular printable characters. Please correct me if I am wrong with that.
So, if I am not wrong about cat, how would you concatenate these two binary files?
Thank you,
LiteHacker
Offline
okay, I figured it out:
cat file1 file2 > concatenatedfile
Offline