fat12 set cluster

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: fat12 set cluster

Post by jal »

abuashraf wrote:I already wrote complete fat12 driver in C,but now I'm writing it in asm
but I'm really having problem with this specific function
So basically your problem is that you can't code assembly. It's pretty stupid then abandoning C.


JAL
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

I'm trying to learn assembly by coding a real mode os,and so far I've learnt alot
and I'm very pleased about that.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: fat12 set cluster

Post by Combuster »

DOS .COM works pretty well too if you want to learn to use basic assembly.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

I wrote a lot of Dos programs,but I'm having trouble with this specific fumction
Could we guys stop going off-topic please...
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: fat12 set cluster

Post by jal »

abuashraf wrote:I wrote a lot of Dos programs,but I'm having trouble with this specific fumction
I really fail to understand that, if you have a working C-version, you are not able to make an assembly one. What is your problem?


JAL
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: fat12 set cluster

Post by DeletedAccount »

http://www.it.lth.se/ssoa/Project1/FAT12Description.pdf :) . You might find this more readable than the official Microsoft specs

Regards
Thomas
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

here's what I have,till now I couldn't solve my problem,
There's somthing wrong in my code,would someone please check it...

Code: Select all


setcluster:
        push    cx dx bx
        mov     cx, ax                  ;copy current cluster
        mov     dx, ax                  ;copy current cluster
        shr     dx, 0x0001              ;divide by two
        add     cx, dx                  ;cx=offset into FAT			
        mov     bx,[es:0x500]           ;address of fat table
        add     bx, cx                  ;index into FAT
        mov     dx, WORD [bx]           ;read two bytes from FAT(old value in dx)
        test    ax, 0x0001
	jnz	.odd
.eve:	
	mov     bx,dx
	and     bx,0xF000               ;bx holds the old value 
	and     word[value],0x0FFF      ;next cluster
	
	or      word[value],bx
	mov     dx,word[value]
	mov     word [bx],dx
	jmp	donexx
.odd:
	mov     bx,dx
	and     bx,0x000F               ;bx holds the old value
	shl     word[value],4   	;next_cluster
	or      word[value],bx
	mov     dx,word[value]
	mov     word [bx],dx            ;save the new value
donexx:
        pop     bx dx cx
        ret

Thanx.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

right now I'm very sure of this function,90% it's fine and nothing wrong with him,
but till now I couldn't change the value in the fat entry.
Also I'm sure that I load FAT table correctly into memory,because I can read
text files even if they are very long.
guys what do you advice me?how can I figure out what's wrong?
how can I debug this problem?
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: fat12 set cluster

Post by xyjamepa »

It's working now... :D
Here's the working code,for anybody else...

Code: Select all

setcluster:
        push     cx 
        mov     cx, ax                  ;copy current cluster 
        mov     dx, ax                  ;copy current cluster 
        shr     dx, 0x0001              ;divide by two 
        add     cx, dx                  ;cx=offset into FAT                      
        mov     bx,[es:0x500]           ;address of fat table 
        add     bx, cx                  ;index into FAT
        push    bx 
        mov     dx, WORD [bx]           ;read two bytes from FAT(old value in dx) 
        test    ax, 0x0001 
        jnz     .odd 
.eve:    
        mov     bx,dx 
        and     bx,0xF000               ;bx holds the old value  
        and     word[value],0x0FFF      ;next cluster 
         
        or      word[value],bx 
        mov     dx,word[value]
        pop     bx 
        mov     word [bx],dx 
        jmp     donexx 
.odd: 
        mov     bx,dx 
        and     bx,0x000F               ;bx holds the old value 
        shl     word[value],4           ;next_cluster 
        or      word[value],bx 
        mov     dx,word[value] 
        pop     bx
        mov     word [bx],dx            ;save the new value 
donexx:          
        pop      cx  
        ret
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Post Reply