Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First OS, a few assembly line explanations

I am writing my first OS boot sector in assembly using NASM. I have it working, it just displays "Hello OS world!" in red letters. Simple enough. I have converted my boot.asm into boot.bin, and that into boot.img. I am using VMWare player, i mounted the boot.img as a floppy drive and booted from there and it works great.However there are a few lines of this assembly code who's purpose I don't understand.

       org  07c00h                         
       mov  ax, cs
       mov  ds, ax
       mov  es, ax
       call DispStr         
       jmp  $           
   DispStr:
       mov  ax, BootMessage
       mov  bp, ax 
       mov  cx, 16  
       mov  ax, 01301h      ; 
       mov  bx, 000ch       ;
       mov  dl, 0           ;
       int  10h             ;
       ret
   BootMessage:     db  "Hello, OS world!"
       times    510-($-$$)  db  0   
       dw   0xaa55              ; 

The lines ending with the semi-colon are the ones that i don't understand. I have done a lot of googling and have been able to figure out the other stuff. I am fairly competent in writing assembly. So for example I know mov ax,01301h moves the 01301h into the AX register. But i don't understand why, or how 01301h is significant. I would guess they are somewhat like parameters for formatting the string, but that is just a guess. Any and all help would be greatly appreciated.

like image 397
mingle Avatar asked Jan 14 '23 09:01

mingle


1 Answers

Check out this page about INT 10H for more information. Those numbers are parameters controlling the behaviour of that interrupt. In your case:

ax = 0x1301 -> ah = 0x13 al = 0x01
bx = 0x000c -> bh = 0x00 bl = 0x0c
cx = 16
dl = 0x00

The AH=0x13 means 'write string', with various other controlling parameters:

AL = write mode -> 1
BL = color -> 0x0c = light red
BH = page number -> 0
CX = string length -> = 16
DH = row -> 0
DL = column -> 0
ES:BP = offset of string -> pointer to BootMessage string
like image 115
Carl Norum Avatar answered Jan 22 '23 04:01

Carl Norum