how do i compile my assembly code into a raw bin file so i can use it in a boot loader?
Posted on 2002-08-03 15:07:12 by Qages
There was a thread about this already. Do a board search :)
Posted on 2002-08-03 15:22:34 by comrade
i did, it came up witth junk. i dont know what keywords to search for
Posted on 2002-08-03 15:34:22 by Qages
what I found is that you have an older version of link that can use 16 bit code. Masm handles that without problems.

Correct me if I'm wrong.
Posted on 2002-08-03 15:39:11 by phueghy
where can i get this 16 bit compiler?
Posted on 2002-08-03 15:42:04 by Qages
as far as i understand it you compile with masm and use the old link version which you can download at iczelions site:
in the downloads section.
Microsoft Linker for those who want to use MASM to code DOS programs. You MUST use this linker instead of the one from MASM32.
Posted on 2002-08-03 15:45:29 by phueghy
I seem to recall to have read that FASM is able to assemble raw code...
Posted on 2002-08-03 16:11:01 by JCP
im a loyal masm user. i dont go for non-standard hll-based compilers like fasm/nasm/spasm. but ive got it working. i seem to have to hex edit out 512 bytes of 0s before the code/boot seg wich is also 512 bytes. anyi deas how to get it only the code?
Posted on 2002-08-03 16:17:32 by Qages
"hll-based compilers like fasm/nasm/spasm" haha. Masm is the most hll of these... anyway, get 16bit linker from iczelions site, then exe2bin from somewhere (it's included in win2k, and it's not hard to write your own).
Posted on 2002-08-03 16:26:54 by f0dder

im a loyal masm user.

I'm loyal to what gets the job done the best... especially when it comes to compilers and assemblers...
Lots of good assembly programmers switched from MASM to FASM in the past weeks... loyalty is for relationship and work relations, not for programming imho. ;)
But I see what you mean... :)

i dont go for non-standard hll-based compilers like fasm/nasm/spasm.

FASM, nasm and spasm HLL based? ?_o
Or did you mean that the hll of these assemblers is "non-standard" (then, to what ? MASM?) and afaik the HLL support in these assemblers is provided by macros, unlike MASM where they are built-in.

Posted on 2002-08-03 16:29:11 by JCP
im having trouble with my boot sector, it shows a jumble of letters, but not the message i want it to display

.model tiny, stdcall

option casemap :none
;-- --------------------------------------------------------------------
; Simple boot program that prints the letter 'H'
; and then hangs
; Joel Gompert 2001
; Disclaimer: I am not responsible for any results of the use of the contents
; of this file


; This is where BIOS loads the bootloader

; Execution begins here

jmp short begin ; jump over the DOS boot record data

; ----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM name & DOS version (8 chars)
brBPS DW 512 ; 000Bh - Bytes/sector
brSPC DB 1 ; 000Dh - Sectors/cluster
brResCount DW 1 ; 000Eh - Reserved (boot) sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSPH DW 18 ; 0018h - Sectors per track
brHPC DW 2 ; 001Ah - Number of Heads
brHidden DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig
brSerialNum DD 404418EAH ; 0027h - Volume serial number (random)
brLabel DB 'randys disk' ; 002Bh - Volume label (11 chars)
brFSID DB 'FAT12 ' ; 0036h - File System ID (8 chars)

; --------------------------------------------
; Boot program code begins here
; --------------------------------------------
; boot code begins at 0x003E

xor ax, ax ; zero out ax
mov ds, ax ; set data segment to base of RAM
mov ss,ax
mov sp, 7D00h
mov bp, sp
mov si, offset msg ; load address of our message
jmp putstr ; print the message

jmp hang ; just loop forever.

;lodsb ; AL = [DS:SI]
mov al, byte ptr DS:[SI]
or al, al ; Set zero flag if al=0
je hang ; jump to putstrd if zero flag is set
mov ah, 0Eh ; video function 0Eh (print char)
mov bx, 0007h ; color
int 10h
inc si
jmp putstr

msg db 'Randys Operating system',0


times db (512 - (offset d - offset entry) - 2) dup(0)

db 55h, 0AAh ;2 byte boot signature
end entry
Posted on 2002-08-03 16:48:08 by Qages
i had to add 7c00 to the offset!!!!!i dont know the tiny memory model, how do i get the complete memory address?
Posted on 2002-08-03 17:07:32 by Qages
I anm glad there are still a few MASM purists who enjoy the sheer low level grunt of MASM.

Posted on 2002-08-04 04:39:59 by hutch--

the boot sector is not read to the base of ram. It is read to 7C00h. You have to set DS accordingly, or add the 7C00h manually as you have done.

You can look here for more info:

Posted on 2002-08-04 08:30:01 by chorus
Yep, better set up your segments manually, and don't reference anything through CS... some BIOSes are broken in the way they set up CS:IP (ie, some have 0:7C00, some have 7C0:0).
Posted on 2002-08-04 10:23:07 by f0dder
This is the start of a working boot sector code:


@pushws macro value
db 6ah
db value

@pushdws macro value
db 66h
db 6ah
db value

_TEXT segment use16 'CODE'

assume ds:_TEXT

org 7C00h

jmp L015A
L7C03 db "MSWIN4.1"
db 11h dup(0)
L7C1C dd 0
db 27h dup(0)
db 11 dup(0) ;label
db 8 dup(0) ;"FAT32 "

xor cx,cx
mov ss,cx
mov sp,7BF8h
mov es,cx
mov bp,0078h

As f0dder tells, better dont use simplified segment directives.
Posted on 2002-08-05 03:51:51 by japheth
Also, you might want to use nasm for bootsector writing... direct binary output and better opcode controls are advantagous when dealing with code like this.
Posted on 2002-08-05 05:50:45 by f0dder
You can get the nice bootsector example here: (I'm sorry, it's written for fasm ;))
Posted on 2002-08-17 06:41:29 by Tomasz Grysztar
used nasm for it, fasm is stupid!
Posted on 2002-08-17 17:05:54 by Qages

used nasm for it, fasm is stupid!

This opinion is stupid, too.
What is stupid about FASM in your opinion?
Posted on 2002-08-17 19:44:57 by bazik