Problems with a simple bootsector

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Elfredo

Problems with a simple bootsector

Post by Elfredo »

Hi all,

i wrote a simple bootsector in NASM . It should just print a message to the screen and then enter a infinite loop. But it doesn?t print anything. Could you please check my code and tell me what i am doing wrong?
Thank you very much !

Code: Select all

                  
ORG 0x7c00                   
   mov ax,0x1301         ; function to write a string on screen
                                           ; al = 01 => update cursor
      mov bx,0x0007         ; page 0, white on black
   mov cx,message_length
           mov dx,0         ; row 0 , col 0
      mov es,dx         ;        
      mov bp,message         ; es:bp is pointing at the string to output
      int 0x10         ; finally invoke the interrupt to output the message
forever:        jmp forever

message: db "Hello , i am a bootsector"
message_length equ $-message

times 510-($$-$) db 0xFF    ; fill space with 0xFF , so that we fit exactly 512 bytes
dw 0xAA55         ; this is the magic signature for the boot-sector
Tom

Re:Problems with a simple bootsector

Post by Tom »

try this:
; test.ASM
; Print "Hello Cyberspace!" on the screen and hang

; Tell the compiler that this is offset 0.
; It isn't offset 0, but it will be after the jump.
[ORG 0]

jmp 07C0h:start ; Goto segment 07C0

; Declare the string that will be printed
msg db 'Hello Cyberspace!'


start:
; Update the segment registers
mov ax, cs
mov ds, ax
mov es, ax


mov si, msg ; Print msg
print:
lodsb ; AL=memory contents at DS:SI

cmp al, 0 ; If AL=0 then hang
je hang

mov ah, 0Eh ; Print AL
mov bx, 7
int 10h

jmp print ; Print next character


hang: ; Hang!
jmp hang
.bdjames

Re:Problems with a simple bootsector

Post by .bdjames »

PrintLoop: mov ah, 0xE
mov bx, 7
int 0x10
Print: lodsb
or al, al
jnz PrintLoop
ret
Elfredo

Re:Problems with a simple bootsector

Post by Elfredo »

but whats wrong with my code please?
PlayOS

Re:Problems with a simple bootsector

Post by PlayOS »

Elfredo wrote:

Code: Select all

       ???        
ORG 0x7c00

mov ax, cs        ; you should initialize the data segment for you variables
mov ds, ax
.....

;times 510-($$-$) db 0xFF ???this line
times 510-($-$$) db 0xFF    ; should be this (look at the $$)

.....
It worked for after these changes.

hope this helps.
Elfredo

Re:Problems with a simple bootsector

Post by Elfredo »

yes, that did help. Thank you !
Post Reply