flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Dex4u 10 Aug 2008, 12:51
You load the whole root dir into a buffer, change the 5th entry in the buffer and write the whole root dir back.
This is fine for fat12 and fat16, but for fat32 you would write just the changed part. |
|||
![]() |
|
abuashraf 10 Aug 2008, 18:43
I tried this:
Code: xor ax,ax ;zero ax mov bx,ax ;zero bx mov dx,ax ;zero dx mov si,ax ;zero si mov di,ax mov bx,[es:0x400] mov ax,19 mov cx,1 call read_sectors call getname mov si,cname mov di,[es:0x400] mov cx,11 push bx xor bx,bx mov bx,160 ;the 5th entry @loop: mov al,byte [si] mov byte [di+bx],al inc si inc di inc bx loop @loop pop bx mov bx,[es:0x400] mov ax,19 mov cx,1 call write_sectors ret I never saw any changes in the root directory ![]() but when I execute the code in the provious post,as you said it changes the whole first sector in the root directory... |
|||
![]() |
|
abuashraf 13 Aug 2008, 01:38
Hi,
now my code works only if I'm writing to entries less than the 4th entry Code: xor ax,ax ;zero ax mov bx,ax ;zero bx mov dx,ax ;zero dx mov si,ax ;zero si mov di,ax mov bx,[es:0x400] ;the buffer mov ax,19 mov cx,1 ;read one sector call read_sectors ;read sectors from floppy call getname ;get file name from users mov si,cname mov bx,[es:0x400] ;save buffer address in bx add bx,96 ;the entry number goes here(3rd entry) ;if i change the value of bx to for example 128 or 160 ;it will not work mov cx,11 yeh: mov al,byte [si] ;save name in buffer mov byte [bx],al inc si inc bx loop yeh mov bx,[es:0x400] ;write the buffer back to the floppy disk mov ax,19 mov cx,1 ;write one sector call write_sectors ret so if I tried to write to the 5th entry 6th... it's not gonna work ![]() |
|||
![]() |
|
Dex4u 14 Aug 2008, 17:30
What is the buffer address set to, is there any chance that BX adds up to more than 0xffff ?, when you add 128 etc.
|
|||
![]() |
|
abuashraf 15 Aug 2008, 00:42
Quote: What is the buffer address set to, I load the sectors in memory at [es:0x400] in my 'read_sectors' function. |
|||
![]() |
|
sinsi 15 Aug 2008, 01:05
Is your buffer at address es:0x400 or is your buffer address stored at [es:0x400]?
|
|||
![]() |
|
abuashraf 15 Aug 2008, 02:29
my buffer address at es:0x400,so [es:0x400] holds the value of my buffer
the content of sector |
|||
![]() |
|
Dex4u 15 Aug 2008, 16:24
If your buffer is at es:0x400 than this code will not work, as your putting whats in that address into BX, than when you add to BX your just add to the content, not the address.
|
|||
![]() |
|
abuashraf 15 Aug 2008, 17:46
humm...how can I fix that?
|
|||
![]() |
|
Dex4u 16 Aug 2008, 16:00
You could try something like this:
Code: xor ax,ax ;zero ax mov bx,ax ;zero bx mov dx,ax ;zero dx mov si,ax ;zero si mov di,ax mov bx,0x400 ;the buffer mov ax,19 mov cx,1 ;read one sector call read_sectors ;read sectors from floppy call getname ;get file name from users mov si,cname mov bx,0x400 ;save buffer address in bx add bx,96 ;the entry number goes here(3rd entry) ;if i change the value of bx to for example 128 or 160 ;it will not work mov cx,11 yeh: mov al,byte [si] ;save name in buffer mov byte [es:bx],al inc si inc bx loop yeh mov bx,0x400 ;write the buffer back to the floppy disk mov ax,19 mov cx,1 ;write one sector call write_sectors ret But we would also need to see your 'write_sectors', 'read_sectors' to be sure, also they need to be in the same segment. |
|||
![]() |
|
abuashraf 17 Aug 2008, 00:54
There was a push instrucion in other function of my os,this push was making the trouble,I erased this push and my code working now.
Thank you guys very much for your help,but there is a question, I never executed the function with the bad push ,how would this push affect my current working func? the function with the bad push was away from being executed,while executing my function to make the new entry... |
|||
![]() |
|
Dex4u 17 Aug 2008, 12:17
Replace the push and pop with 4 nop eg:
Code: nop nop nop nop If it stops work again, then your problem maybe that as your code grows, it move into the next segment etc. |
|||
![]() |
|
abuashraf 17 Aug 2008, 17:39
No,it did'nt work,my os just frezze...
Also every time I try to add a new instructions,my os either frezze or reboot....even if the new code was a single instruction. ![]() how can I fix this problem? |
|||
![]() |
|
edfed 18 Aug 2008, 16:56
u can try this:
BOOT.ASM Code: ;version 13/05/2008 15:31;;;;; comloader: use16 org 7c00h push cs pop ds mov si,reboot mov [si+disk.drv],dl call disk mov word[si+disk.off],there jmp far dword[si+disk.off] there: push cs pop ds mov si,kernel mov ax,[si+disk.seg] mov es,ax xor bx,bx mov cl,psp.end-psp mov di,psp @@: mov ax,[di+bx] mov [es:bx],ax add bx,2 dec cl jne @b mov [si+disk.drv],dl call disk mov word [si+disk.off],0 call far dword[si+disk.off] push cs pop ds mov bx,0b101h call cls mov si,reboot mov dword[si+disk.off],7c00h mov byte[si+disk.drv],80h call disk jmp far dword[si+disk.off] cls: mov di,80*25*2-2 mov ax,0b800h mov es,ax @@: mov [es:di],bx sub di,2 jnl @b ret psp: push cs pop ds mov ax,100h call ax retf .end: align 4 reboot: ; dd disk dd 00010002h,1,1000h:7c00h,0;,0 kernel:; dd disk dd 007f0002h,2,2000h:0100h,0;,0 include 'disk.inc' ; free = 510-(padding-$$) padding rb free dw 0aa55h ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; macro from an Adam Marquis's bootsector , an user of FASM board DISK.INC Code: disk: ;.call=0 ; not usefull for bootloader .cmd=0;4 ; then, relocate the fields .drv=1;5 ; and will save 4 bytes by objects. .cnt=2;6 .s=4;8 .h=5;9 .c=6;10 .off=8;12 .seg=10;14 .s0=12;16 .h0=13;17 .c0=14;18 ;.kb0=20 ; not usefull for now, save 4 bytes + source code. call .id mov al,[si+.s] mov ah,[si+.h] mov bx,[si+.c] mov cx,[si+.cnt] mov dx,[si+.off] push cx dx es .next: dec word[si+.cnt] jl .end push ax bx mov cx,bx mov bl,cl mov cl,ch mov ch,bl shl cl,6 and cl,0c0h or cl,al mov dh,ah pushaw call .atom jnc @f popaw pushaw call .atom jnc @f popaw pushaw call .atom jnc @f .error: popaw pop bx ax clc jmp .tchao @@: add word[si+.off],512 popaw pop bx ax inc al cmp al,[si+.s0] jne @f mov al,1 inc ah cmp ah,[si+.h0] jl @f mov ah,0 inc bx cmp bx,[si+.c0] jl .next mov bx,0 @@: jmp .next .atom: call .reset mov bx,[si+.seg] mov es,bx mov bx,[si+.off] mov ah,[si+.cmd] mov al,1 mov dl,[si+.drv] int 13h ret .reset: mov dl,[si+.drv] mov ah,0 int 13h ret @@: clc ret .id: cmp byte[si+.drv],0 jnl .floppy call .reset jc @b mov ah,8 mov dl,[si+.drv] int 13h inc dh mov [si+.h0],dh mov bx,cx and cl,not 0c0h mov [si+.s0],cl mov cl,ch mov ch,bl shr ch,6 inc cx mov [si+.c0],cx @@: ; movzx ax,byte[si+.s0] ; movzx bx,byte[si+.h0] ; mov cx,word[si+.c0] ; imul ax,bx ; imul ax,cx ; shr ax,1 ; mov [si+.kb0],ax stc ret .floppy: mov word[si+.c0],80 mov byte[si+.h0],2 mov byte[si+.s0],18 jmp @b .end: stc .tchao: pop es dx cx mov [si+.off],dx mov [si+.cnt],cx ret it was hard to debug, but now, it's stable. many problems when using int13h with more than 1 sector on floppy drives. then, read/write sectors one by one is prefered. otherwise, i don't see where can be your pb as you didn't post it integrally. Last edited by edfed on 18 Aug 2008, 17:55; edited 1 time in total |
|||
![]() |
|
Dex4u 18 Aug 2008, 17:37
We need to know where your kernel is load to and what you put in you segment regs eg: DS, ES etc.
This is the main problem with real-mode that's why its best to move to pmode. Also i like bootprog as a boot loader , as it can load a com or mz exe http://alexfru.chat.ru/epm.html#bootprog |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.