flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Echo MBR

Author
Thread Post new topic Reply to topic
da_man



Joined: 12 Oct 2004
Posts: 3
da_man 12 Oct 2004, 21:23
hello,

i am new to assembler and to get used to it i tried to write a simple bootloader which spits out a message, reads the MBR and echos it to the screen.
the first two points seem to be no problem, but being new to assembler i get stuck in echoing the data of the MBR to the screen.

here is my code (the important parts):
Code:
[...]
      mov ax, 0x9000
        mov es, ax

   readsec:
     ; ES:BX = Location ; AX = Sector

        xor bx,bx

       mov ax, 0x201
       mov cx, 0x0001
      mov dx, 0x0080

  int 0x13
    
    mov si, [es:bx]
 call print


    print:
            lodsb       
            or al,al
            jz printd
            mov ah,0x0E
            mov bx,0x0007
            int 0x10
            jmp print
  printd:    retn
    


could you give me a hint? the print function won't work when used with si = [es:bx]. (the MBR is filled with FFFFFF00 for testing purposes. bochsdbg indicates that the memory address is indeed filled with the contents of the MBR, but i am lacking the skills to display them on screen)
Post 12 Oct 2004, 21:23
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 13 Oct 2004, 05:50
Hi!

I just took a quick look at your code and I think your problem is that lodsb (etc.) instructions use (as far as I remember now) ds:si segment register pair and stosb (etc.) instructions es:di pair.

I think you might try setting ds segment pointing to 0x9000 along es segment. But unfortunately I haven't had time to test this.

regards
Mac2004
Post 13 Oct 2004, 05:50
View user's profile Send private message Reply with quote
da_man



Joined: 12 Oct 2004
Posts: 3
da_man 13 Oct 2004, 14:51
setting ds to 0x9000 hangs the program.

as i understand the print function above it should copy [si] to al and inrement si by one. then it checks if al is empty (if yes it returns), after these steps it copies the parameters for int 0x10 to the corresponding registers and finally it triggers int 0x10.

but i can't figure out why it doesn't print anything.
how would you solve this problem?
Post 13 Oct 2004, 14:51
View user's profile Send private message Reply with quote
drh3xx



Joined: 11 Sep 2004
Posts: 34
drh3xx 13 Oct 2004, 15:05
Hi, I have no idea why loading 0x9000 into ds is hanging bochs that is strange.

Because you know the length of the MBR (512 bytes) I'd loop through the lodsb/print value routine. The way you have it at the minute checking for the null value will stop printing as soon as it encounters a byte set to 0 so it might not print all of the MBR.

Also mov si,[es:bx] loads the value at that address into si. You want to simply set ds=es and then mov si,bx.

hope you get your code working soon.
Post 13 Oct 2004, 15:05
View user's profile Send private message Reply with quote
da_man



Joined: 12 Oct 2004
Posts: 3
da_man 13 Oct 2004, 15:39
sorry i messed something up.
it works now. i replaced mov si,[es:bx] with mov si, bx and set ds to 0x9000.
the downside is, that i can't use the print function to print a message embedded in the code. should i code another function, that avoids lodsb and prints out the data 'manually' doing what lodsb does, but utilizing the es register?
i'd also like to know how it is possible to not display the data converted to ascii, but the raw hex values.

thank you for helping me.

the whole code is:
Code:
[BITS 16]
[ORG 0]

    jmp 07C0h:start

    ; Declare the string that will be printed
    msg     db  'Hello',13,10,0


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



            mov si, msg     ; Print msg
         call print

    readsec:
;         ; ES:BX = Location ; AX = Sector

        xor bx,bx

       mov ax, 0x201
       mov cx, 0x0001
      mov dx, 0x0080

  int 0x13
    
    mov si, bx
  call print
  jmp hang


    

    print:
            lodsb     
            or al,al
            jz printd
            mov ah,0x0E
            mov bx,0x0007
            int 0x10
            jmp print
  printd:    retn                       
          
   
    hang:                   ; Hang!
            jmp hang
  
    
Post 13 Oct 2004, 15:39
View user's profile Send private message Reply with quote
drh3xx



Joined: 11 Sep 2004
Posts: 34
drh3xx 13 Oct 2004, 18:20
You need to setup a table of db's '0123456789abcdef'
and then use the low nibble (bits 0->3) of al and use that value as an offset in to the table. With me so far? then print the character it points to using the bios call you already use.

IMPORTANT: Remember the first character you want to print is the value in bits 4->7.

If you get stuck let me know. I don't want to just do the code for you as you'd not learn anything Smile
Post 13 Oct 2004, 18:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.