Re: read floppy problem




"leilei" <spamtrap@xxxxxxxxxx> wrote in message
news:2c0243cc-2877-4514-bf1e-66d437e8c9ab@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi , I am writting a program which read a sector from floppy to
memroy.here is the code:

SubRoutine_ReadSector:
push bp
mov bp, sp
push ax
push bx
push cx
push dx

mov ax, [bp + 6] ;Sector Number ; ax = lets say 100
push bx ;
mov bl, [BPB_SecPerTrk] ; ; bl = 18
div bl ; al = 5, ah = 10
inc ah ; ah = 11
mov cl, ah ; cl = 11
mov dh, al ; dh = 5
shr al, 1 ; al = 2
mov ch, al ; ch = 2
and dh, 1 ; dh = 1
pop bx
mov dl, [BS_DrvNum] ; dl = 0

; Sector = (LBA mod SPT) + 1 (SPT = Sectors per Track)
; Head = (LBA / SPT) mod Heads
; Cylinder = (LBA / SPT) / Heads

LBA = 100
Sector = 11
Head = 1
Cyl = 2

Well, your math may be correct, but I don't think the code
looks right.

.GoOnReading:
mov ah, 2
mov al, byte [bp + 4] ; How many sectors.

'byte [bp+4]' points to the callers return address, doesn't it? Or at least
half of it.

Second, where do you set ES:BX? Do you set it before you call this
function? If so, why do you just pass the LBA in ax rather than using
the stack. IMO, either pass all on the stack, or none on the stack.

int 13h
jc .GoOnReading ;if any problem happend, continue to read.

This will go on for ever if it never reads correctly, or you don't
send it valid args. Try a count of 3 tries or so.

pop dx
pop cx
pop bx
pop ax
pop bp
ret 4

Why do you pop off 4 bytes when you only push on 2? Or did I
miss something?

After I call this routine, I always get wrong answer.
The correct datas on the floppy is:
4C 4F 41 44 45 52 20 20 42 49 4E 20 00 00 00 00 00 00 00 00 00 00 DD
B5 35 ??
But the actual datas in memory is:
4C 4F 41 44 45 52 42 49 4E 20 00 00 00 00 00 00 00 00 35??

After compare these datas, I found there are some datas lost:
4C 4F 41 44 45 52 20 20 42 49 4E 20 00 00 00 00 00 00 00 00 00 00 DD
B5 35
4C 4F 41 44 45 52 42 49 4E 20 00 00 00 00 00 00 00
00 35

Can anyone give me some help?why some datas lost, some not.

Hope this helps,
Ben

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.frontiernet.net/~fys/index.htm
To reply by email, please remove the zzzzzz's

Batteries not included, some assembly required.

.



Relevant Pages

  • Re: read floppy problem
    ... to read the sector in question: ... mov ah,2; read sector function ... The correct datas on the floppy is: ...
    (comp.arch.embedded)
  • read floppy problem
    ... I am writting a program which read a sector from floppy to ... The correct datas on the floppy is: ... Can anyone give me some help?why some datas lost, ...
    (comp.lang.asm.x86)
  • read floppy problem
    ... I am writting a program which read a sector from floppy to ... The correct datas on the floppy is: ... Can anyone give me some help?why some datas lost, ...
    (comp.arch.embedded)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)