Hello,
I want to write a *.bin(Assembly compiled file) to an floppy drive, but i don't know how to do this, remember that i have to write to the cylinder 0, head 0 and sector 1, because it's an boot program, only if needed here is the code:

; directive to create BOOT file:
#make_boot#

; Boot record is loaded at 0000:7C00,
; so inform compiler to make required
; corrections:
ORG 7C00h

PUSH    CS   ; make sure DS=CS
POP     DS

; load message address into SI register:
LEA SI, msg

; teletype function id:
MOV AH, 0Eh

print:   MOV AL, [SI]
         CMP AL, 0
         JZ done
         INT 10h   ; print using teletype.
         INC SI
         JMP print

; wait for 'any key':
done:      MOV AH, 0
           INT 16h


; store magic value at 0040h:0072h:
;   0000h - cold boot.
;   1234h - warm boot.
MOV     AX, 0040h
MOV     DS, AX
MOV     w.[0072h], 0000h ; cold boot.

JMP	0FFFFh:0000h	 ; reboot!


new_line EQU 13, 10

msg DB  'Hello This is My First Boot Program!'
    DB  new_line, 'Press any key to reboot', 0

Thanks,
Nathan Paulino Campos

Recommended Answers

All 2 Replies

Hello, you could read your bare binary file into a segment
of memory and write it out to the disk drive using
interrupt 13h function 03h (write sectors),
get ralf browns interrupt list!
You would need to write it out to head 0,cylinder 0,sector 1.
The last word of the sector must contain the signature
0xAA55 at offset 01FE [55] - 01FF [AA] and the boot loader
must fit onto one 512 byte sector.

I used to make a disk image using 16-bit NASM and boot
the 1.44MB floppy images using Bochs x86 emulator,
I used the following directives to use the assembler
to produce a floppy disk image:

times 0200h - 2 - ($ - $$) db 0 
;Boot signature
dw 0aa55h   

; fill rest of binary image to 1.44MB, to make disk image.

times 1474560 - ($ - $$) db 0

This allowed me to quickly debug and test my bootloader.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.