flat assembler
Message board for the users of flat assembler.

Index > OS Construction > root directory(memory buffer problem)

Author
Thread Post new topic Reply to topic
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 06 Oct 2008, 02:26
Hi,

I'm writing a real mode os,and I've finished FAT12 driver and started
with some INTs support,but unfortunatelly I discovered some bugs
in my code,so I had to rewrite the whole thing from the begining...

In the past when I load some sectors off the disk to the memory
I used this combinaion ,for example [es:0x200],but that gave me alot of troubles,so now when I try to print the content of the root directory
I get garbage stuff...
here's the code:
Code:
showdir:
        push    es   
       xor     ax,ax                   ;zero ax
        mov     cx,ax                   ;zero cx
        mov     dx,ax                   ;zero dx
        mov     bx,0x200            ;set the buffer (es:bx)
        mov     es,bx                    ;es=0x200,bx=0x00
        xor     bx,bx
        mov     ax,19                   ;first sector of the root directory
        mov     cx,14                   ;root directory occupy 14 sectors                
        call    read_sectors   
   call    printbuffer 
        pop     es
  ret
    


Code:
printbuffer:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     si,ax                   ;zero di
        mov     bx,0x200
        mov     es,bx
        mov     si,0x00                 ;si points to the buffer

        mov     cx,224                  ;number of root directory entries
  @loop: 
        test    byte[si+0x0b],1 shl 3   ;is it a volume label? 
        jnz     del                     ;don't print it 
        cmp     byte [si],0xE5          ;is it deleted file?
        je      del                     ;yes, don't print it
        cmp     byte [si],0x00          ;is this the end of files/directories?
        je      quit                    ;yes,quit
    no:                                 ;no...
        push    cx                      ;start printing the names
        mov     cx,11
        call    printname
        pop     cx

        add     si,21                   ;go to the next entry
        jmp     again                   ;continue printing!
     del:
        add     si,32                          
     again:   
        loop    @loop                   ;continue printing!                      
quit:
        
        ret                             ;return!
;-----------------------------------------------;
;prints the name of files/directories           ;
;cx=length of the name                          ;
;-----------------------------------------------;                           
printname:
        mov     al,[si]                 ;the buffer address
        call    putc
        inc     si
        loop    printname
        call    newline                 ;print newline    
        ret                             ;return!
    

every time I execute this code I get garbage.

i'm very sure my functions work fine,and I'm sure the problem is in the buffer address,I think I'm starting the printing from the wrong address

would you help me...


Last edited by abuashraf on 06 Oct 2008, 03:27; edited 1 time in total
Post 06 Oct 2008, 02:26
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 06 Oct 2008, 02:42
Quote:

would you help me...

I think you should post print and read_sectors too.

Code:
        test    byte[si+0x0b],1 shl 3   ;is it a volume label?      
Is DS==ES at this point?
Post 06 Oct 2008, 02:42
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 06 Oct 2008, 03:28
Code:
read_sectors:
  @main:
        mov     di,5
  @sectorloop:
        push    ax bx cx dx
        call    lbachs
        mov     ah, 0x02                    ; BIOS read sector
        mov     al, 0x01                    ; read one sector
        mov     ch, BYTE [track]            ; track
        mov     cl, BYTE [sector]           ; sector
        mov     dh, BYTE [head]             ; head
        mov     dl, 0                       ; drive
        int     0x13                        ; invoke BIOS
        jnc     @success
        xor     ax,ax
        int     0x13
        dec     di
        pop     dx cx bx ax
        jnz     @sectorloop
        int     0x18
@success:
        pop     dx cx bx ax
        add     bx,0x200                ;add 512 bytes to buffer
        inc     ax
        loop    @main
        ret
    


Code:
lbachs:
        push    dx bx ax cx              
        xor     dx,dx                       
        mov     bx, 18              
        div     bx                  
        inc     dx                  
        push    dx                  

        xor     dx,dx                   
        mov     bx, 2               
        div     bx                  

        mov     cx,ax                   
        mov     bx,dx                       
        pop     ax                  
                                                           
        mov     [sector],al             
        mov     [head],bl 
        mov    [track],cl 
        pop     cx ax bx dx 
        ret
    

I'm pretty sure that this functions are fine,but I think I'm printing
from the wrong address... Confused

Also I deleted the print function,no need for it.
Post 06 Oct 2008, 03:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 06 Oct 2008, 03:42
With a quick look at the code seems to be OK, but I still don't see where do you set DS with the same value ES has (0x200).

For example, with the source you have shown so far "mov al,[si] ;the buffer address" accesses 0x????:SI address, where "????" means unknown.
Post 06 Oct 2008, 03:42
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 06 Oct 2008, 03:58
Yes, somewhere along the line you need
Code:
        mov     bx,0x200
        mov     ds,bx
    

Any reference to [si] assumes [ds:si]
Instead of changing DS with the above code you can use [es:si], which is probably better.
Post 06 Oct 2008, 03:58
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 07 Oct 2008, 02:07
Yeb...that was the problem, Smile
thank you guys for your help.
Post 07 Oct 2008, 02:07
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.