flat assembler
Message board for the users of flat assembler.

Index > Main > IS this correct?(aligning things and getting file size)

Thread Post new topic Reply to topic

Joined: 12 Nov 2006
Posts: 86
Location: usa
Hi, I'm generating my own floppy disk images, because I am using a custom FS..
now what I want is to import the contents of a file(using the file directive) and then get the size of this file so that I can align it on a 512 byte sector...like if the file is 580 bytes, I want it to round up to 1024 on the next file I make..

here is my code:(it's a bit messy)
;this is just a file taking advantage of FASM and this makes a simple
;StoopidFS filesystem..this generates a complete raw bianry image..

file 'boot.bin' ;it's already aligned!

db 0x3C ;file verification byte
dw (((first_file_end-first_file)/512)+1) ;calculate the size of the
.fname: db "kernel.bin" ;the filename string
times 16-($-.fname) db 0 ;fill in the rest of the 16bytes for the filename
dd 0x00000000 ;actual filesize(unused)
db 0x0 ;attribute byte
;;;;Actual File;;;;;

file 'kernel.bin'


times ((((first_file_end-first_file)/512)+1)*512) -($-first_file) ;this should fill in the rest of the sector with 0s to align it for adding more files
;hopefully it works..

times 1474560- ($-image_start)  db 0 ;this makes sure our generated image file is exactly 1.44mb

x86 CPU Emulation library: http://sourceforge.net/projects/x86lib
Post 06 Jun 2007, 20:33
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.