My bootsector

Hi there. There comes a time early in the life of every assembly language programmer to achieve the ultimate freedom, and print 'Hello World' without the aid of an operating system ;)

Anyway, I have a little problem. It works fine in Virtual PC, but it won't on any of the real PCs I've tried it on. Am I using outdated BIOS calls? I would prefer to change the screen mode and cursor without the BIOS, but I don't know how.

[code]
bits 16
org 0x7C00

start
; set screen mode
mov al, 0x2 ; mode 2h
mov ah, 0
int 0x10

; set cursor off
mov ah, 0x1
mov ch, 32 ; 32 or above = off
int 0x10

mov ax, 0xB800
mov es, ax ; video segment
mov di, 0 ; video offset

mov ah, 0x1A ; green text on blue
mov al, ' ' ; space

; fill screen with colour
.L1
cmp di, 80 * 25 * 2
jge .L2
mov [es:di], ax
add di, 2
jmp .L1
.L2

; print message
mov si, msg
mov di, (33 + (11 * 80)) * 2
.L3
mov al, [si]
test al, al
jz .L4
mov [es:di], al
add di, 2
inc si
jmp .L3
.L4

end
jmp end

msg db "Hello, World.", 0

times 510-($-$$) db 0 ; padding
dw 0xAA55 ; magic number
[/code]

Comments

  • I got it! I forgot to set up the data segment:

    [code]
    mov ax, 0x0
    mov ds, ax
    [/code]

    One little niggle though. I know 0x7C00 is the location the program is loaded to, but what effect does 'org 0x7C00' have on the code generated by NASM? Does it offset every memory address by this?

  • : One little niggle though. I know 0x7C00 is the location the program is loaded to, but what effect does 'org 0x7C00' have on the code generated by NASM? Does it offset every memory address by this?
    :

    an ORG statement places code in memory at that location, usually by buffering the file with 0's when DOS loads it.

    Since the BIOS is taking your code off the 1st sector of the floppy disk and placing it at 0:7c00 before executing it, you should be able to get away with not have an ORG statement at all.

    -jeff!
  • : Since the BIOS is taking your code off the 1st sector of the floppy disk and placing it at 0:7c00 before executing it, you should be able to get away with not have an ORG statement at all.

    I think not - there are a couple of absolute jumps in his code that have to be resolved by the linker to match the load address. Now if all his jumps were relative, that would be different.

  • [b][red]This message was edited by shaurz at 2003-7-25 14:30:36[/red][/b][hr]
    [b][red]This message was edited by shaurz at 2003-7-25 14:30:27[/red][/b][hr]
    : here is a complete example of Tiny OS:
    :
    : http://www.programmersheaven.com/search/download.asp?FileID=22432
    :
    :
    :

    Thanks, I'm interested in taking this further, so I'll have a good look at that, it will be the next step. I'm also having a peek at Retro OS and Unununium at the mo', for ideas and code ;)

    My short term goals are getting a FAT12 and floppy driver working, getting into protected mode and the beginnings of a mini OS, with a Forth system.

    Eventually, some time in the future, I want an ATAPI driver to load from HD (with FAT32 or ext2 support), a shell, a dynamic memory allocator and a basic task scheduler for multi-tasking. I'd like these all to be seperate programs, instead of one big kernel. And an interrupt based messaging system. That would be cool :)




  • :
    : an ORG statement places code in memory at that location, usually by buffering the file with 0's when DOS loads it.
    :
    : Since the BIOS is taking your code off the 1st sector of the floppy disk and placing it at 0:7c00 before executing it, you should be able to get away with not have an ORG statement at all.
    The easiest thing to do is what most programmers do....

    ORG 7C0h
    Start: MOV AX, 07C0h ; Segment
    PUSH AX
    MOV AX, OFFSET Label1 ; Offset
    PUSH AX
    RETF ; FAR JMP to 07C0h:Label1

    Label1: ; From this point on, your executing at 7c0: (0-based)

    Your offsets are correct, you don't have padding, you can assemble to a .bin file without having to strip any un-necessary 0's, and its easiest to save to disk....
  • NASM doesn't pad your code with zeroes when you use ORG like others do. All it does is add that number to absolute addresses, such as memory access instructions using immediate memory locations specified using labels.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories