1

Just making a simple OS as a beginner for my assembly project. I have this very simple bootloader which prints a character B and reads the second sector (kernel) from drive and loads it at 10000h memory address

.model tiny
ORG 7C00h
.code
start:
    cli
    mov ax, 07B0h
    mov ss, ax
    mov sp, 00FFh
    sti
    mov ax, cs
    mov ds, ax

    mov ah, 0Eh 
    mov al, 'B' 
    int 10h   

    ; Reading kernel
    mov ah, 02h
    mov al, 1   
    mov ch, 0       ; cylinder
    mov cl, 2  
    mov dh, 0       ; head
    mov dl, 0 
    mov bx, 0
    mov ax, 1000h
    mov es, ax
    int 13h

    jc disk_error
    
    mov ah, 0Eh
    mov al, 'J'
    int 10h 

    jmp es:[bx]

disk_error:
    mov ah, 0Eh
    mov al, 'E'
    int 10h

db 510-($-start) dup(0)
dw 0AA55h
end start

I'm using qemu to test, it is printing B and J but not K or anything I try to print or do in kernel:

.model tiny
org 0
.code
start:
    cli
    mov ax, 07B0h
    mov ss, ax
    mov sp, 00FFh
    sti
    mov ax, cs
    mov ds, ax

    mov ah, 0Eh 
    mov al, 'K' 
    mov bh, 0    
    mov bl, 7 
    int 10h 

    jmp $

db 512 - ($ - start) dup(0)
end start

I can't find any resource which uses MASM to develop an OS all resources are on NASM which is not part of our course. Bootloader seems to work fine but can't seem to figure out if jmp is not working or if something's wrong in kernel file.

5
  • 1
    ah and al, which you set up for int 13h, are both part of ax which you overwrite to initialise es. Change the order of writes so ax has 0201h at int 13h time. (jmp es:[bx] is wrong too.) Commented Apr 12 at 21:05
  • @ecm oh, my bad its funny I missed this haha. Thanks alot for point it out. And for far jmp would pushing segment and offset into stack and then return far using retf work? Commented Apr 12 at 21:28
  • retf, iret, and jmp all can work, albeit using the correct forms for MASM may be more complicated than on NASM. jmp 1000h:0 would be the correct direct/immediate far jump for NASM to set cs to 1000h and ip to 0. Commented Apr 12 at 21:35
  • @ecm Thanks alot man. It worked, I first assigned ax to es at top and then changed its value below for int 13h and for jmp I used retf and its now finally working haha Commented Apr 13 at 9:04
  • I'm not a "man". Commented Apr 13 at 10:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.