Page 1 of 1

Problems with a simple bootsector

Posted: Thu Nov 07, 2002 4:32 pm
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

Re:Problems with a simple bootsector

Posted: Thu Nov 07, 2002 5:50 pm
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

Re:Problems with a simple bootsector

Posted: Thu Nov 07, 2002 6:35 pm
by .bdjames
PrintLoop: mov ah, 0xE
mov bx, 7
int 0x10
Print: lodsb
or al, al
jnz PrintLoop
ret

Re:Problems with a simple bootsector

Posted: Thu Nov 07, 2002 7:07 pm
by Elfredo
but whats wrong with my code please?

Re:Problems with a simple bootsector

Posted: Fri Nov 08, 2002 3:24 am
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.

Re:Problems with a simple bootsector

Posted: Fri Nov 08, 2002 8:09 am
by Elfredo
yes, that did help. Thank you !