flat assembler
Message board for the users of flat assembler.

Index > OS Construction > first free entry(fat12)

Author
Thread Post new topic Reply to topic
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
Hi,

I'm trying to get the first free entry of the root directory for fat12 file system,but i'm not quite sure if my code is correct ,it keeps giving me the
number 1 no matter how I add file,delete them or do any changing in the floppy image.

could you please guys take a look at it...

Code:
;-----------------------------------------------;
;return the first free entry in Ax              ;
;-----------------------------------------------;        
ffentry:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax                   ;zero di

        mov     di,[es:0x400]           ;di points to the buffer
        
  
        mov     cx,16                  
        xor     ax,ax
  @@.loop: 
        inc     dx                      ;dx points to the first free entry
        test    byte[di+0x0b],1 shl 3   ;is it a volume label? 
        jnz     @nextentry              ;go to the next entry
        mov     al,[di+bx]              ;fetch chars from the buffer
        cmp     al,0xE5                 ;is it deleted file?
        je      @del                    ;yes
        cmp     al,0                    ;is this end of files/directories?
        je      @del
     @del:
        mov     ax,dx                   ;ax=first free entry
        jmp     @@.quit                 ;returb
    @nextentry:   
        add     bx,32                   ;go to the next entry                 
               
     @@.again:   
        loop    @@.loop                   
     
@@.quit:
        ret
    


Thanx.
Post 05 Aug 2008, 08:31
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Is the buffer Address store at es:0x400 or is the buffer at es:0x400, because if the buffer is at es:0x400 try this code
Code:
;-----------------------------------------------;;return the first free entry in Ax              ;;-----------------------------------------------;        ffentry:        xor     ax,ax                   ;zero ax        mov     bx,ax                   ;zero bx        mov     dx,ax                   ;zero dx        mov     si,ax                   ;zero si        mov     di,ax                   ;zero di        mov     di,0x400 ;[es:0x400]           ;di points to the buffer                  mov     cx,16                          xor     ax,ax  @@.loop:         inc     dx                      ;dx points to the first free entry        test    byte[es:di+11],1 shl 3   ;is it a volume label?         jnz     @nextentry              ;go to the next entry        mov     al,[es:di+bx]              ;fetch chars from the buffer        cmp     al,0xE5                 ;is it deleted file?        je      @del                    ;yes        cmp     al,0                    ;is this end of files/directories?        je      @del     @del:        mov     ax,dx                   ;ax=first free entry        jmp     @@.quit                 ;returb    @nextentry:           add     bx,32                   ;go to the next entry                                     @@.again:           loop    @@.loop                        @@.quit:        ret    

If not, than yours is OK
Post 05 Aug 2008, 18:16
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
unfortunatelly it gave me the same result which is 1,
here's the first part of my function:
Code:
        mov    bx,[es:0x400]           ;the buffer
     xor     ax,ax                   ;zero ax
        mov     cx,ax                   ;zero cx
        mov     dx,ax                   ;zero dx
        mov     ax,19                   ;first sector of the root directory
        mov     cx,14                   ;root directory occupy 14 sectors                  
        call    read_sectors          ;read 14 sectors
        call    ffentry                   ;get first free entry                 
        call    int_to_string           ;print it
        ret      
Post 06 Aug 2008, 07:10
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Does your "int_to_string" function work OK ?, try this just incase
Code:
;-------------------------------------;;convert number into string           ;;where: AX=num ,                      ;;-------------------------------------;int_to_string:     pushad        mov   ebx,eax shr   eax,8   call  write_hex8      mov   eax,ebx call  write_hex8      popad ret ;----------------------------------------------------; ; write hex                                          ; ;----------------------------------------------------;write_hex8:     push  eax     push  eax     shr   al,4                                            call  hexget                                          call  print_char      pop   eax     call  hexget                                          call  print_char      pop   eax     rethexget:    and   eax,0x0000000f  or    eax,0x00000030  cmp   eax,0x39        ja    add7    retadd7:  add   eax,7                   retprint_char:        mov     ah,0Eh                int     10h                   ret                         
Post 06 Aug 2008, 14:56
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
thank you Dex for your help,anyway I tried your "int_to_string"
function and I got the same result which is 1,I'm really confused Confused
Post 07 Aug 2008, 00:29
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Check your conditional jump 'je @del'. Only if it's a volume label does it not go to @del:. Maybe change to this or similar...

Code:
;[snip]
  @@.loop: 
        inc     dx                      ;dx points to the first free entry
        test    byte[es:di+11],1 shl 3   ;is it a volume label? 
        jnz     @nextentry              ;go to the next entry
        mov     al,[es:di+bx]              ;fetch chars from the buffer
        cmp     al,0xE5                 ;is it deleted file?
        je      @del                    ;yes
        cmp     al,0                    ;is this end of files/directories?
        jnz      @nextentry             ;<---- from je @del
     @del:
        mov     ax,dx                   ;ax=first free entry
        jmp     @@.quit                 ;returb
    @nextentry:   
        add     bx,32                   ;go to the next entry                 
               
     @@.again:   
        loop    @@.loop                   
     
@@.quit:
        ret
    
Edited.. my bad English Shocked
Post 07 Aug 2008, 03:33
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
I would use your int_to_string function and dump some of the regs, eg: DI AND AL, also put a
Code:
push axxor ax,axint 16hpop ax    

after each reg dump so you can step through the code.
Also add this after this label nextentry:
Code:
nextentry:         pusha        mov al,"V"        mov ah,0Eh                      int 10h         popa        

So we know if it gets called.
Post 07 Aug 2008, 20:30
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
It's working now,thank you guys for your help...
here's the code:
Code:
ffentry:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax                   ;zero di
        mov     di,[es:0x400]           ;di points to the buffer
        mov     cx,224                  ;number of root directory entries
  @@.loop: 
        inc     dx
        test    byte[di+0x0b],1 shl 3   ;is it a volume label? 
        jnz     volume                  
        cmp     byte [di],0xE5          ;is it deleted file?
        je      @del                    ;yes,
        cmp     byte [di],0x00          ;is this the end of files/directories?
        je      @del                    ;yes,

        add     di,32                   ;go to the next entry
        jmp     @@.again                ;continue looping
     @del:
        mov     ax,dx                   ;save the first free entry in ax
        jmp     @@.quit                 ;quit 
     volume:                            ;it is a volume label...
        add     di,32                   ;just go to the next entry         
    @@.again:   
        loop    @@.loop                 ;continue looping!                      
@@.quit:
        ret                             ;return    
Post 08 Aug 2008, 08:39
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.