Could anyone write a sample of read on floppy disk with int 13h? I have some problem with the parameter CX.
I tried to read the first sector of the floppy. I believe the first sector is on track 0, head 0 isn't it?
This is what I wrote:
mov ah,0x02
mov al,0x01 - 1 sector only to read
mov dh,0x0 - head 0
mov dl,0x0 - floppy drive
mov cx,0x00400 - sector 1 on track 0 *
int 0x13
* I thought in this way:
sector hight low track
cx 012345 67 89abcdef - bits of CX
000001 00 00000000
first sec track 0
Is there any error??? (I think it is )
Thank you
Comet - Italy
Am I stupid? (disk i/o question 2)
Re:Am I stupid? (disk i/o question 2)
The problem is that you've got both the bit order and the byte order reversed. The correct bit order is
CL CH
76543210 | FEDCBA98
00000001 | 00000000
0x01 | 0x00
However, since you wrote it as a single number, rather than two successive bytes, the assembler automagically swaps the bytes to the 'correct' order, so that the high-order byte of the number goes to CH and the low-order byte to CL. Thus,
MOV CX, 0x0001
assembles to
B9 01 00
(B9 is the opcode for "MOV CX, immediate_word").
Actually, you probably would be better off treating the two halves of CX separately, even given the extra two cylinder bits in CL. Given what I've said here, you can see that for a disk with more than 256 cylinders, the split is rather awkward to show as a single word, as the bit wrap not to the low bits of the low word but to the high bits. for example, to read cyl 511, sector 34 of a hard disk, it would be
CL CH
76 543210 | FEDCBA98
01 100100 | 11111111
0x64 | 0xFF
which as a single number comes out to the rather enigmatic 0x0FF64. This obscures the relationship bettween them; it would be better to do something like:
In any case, this is never relevant in the case of a floppy disk (no standard floppy has more than 80 cylinders AFAIK), while on a hard drive there are other complications anyway.
CCAW (Comments and Corrections Are Welcome).
CL CH
76543210 | FEDCBA98
00000001 | 00000000
0x01 | 0x00
However, since you wrote it as a single number, rather than two successive bytes, the assembler automagically swaps the bytes to the 'correct' order, so that the high-order byte of the number goes to CH and the low-order byte to CL. Thus,
MOV CX, 0x0001
assembles to
B9 01 00
(B9 is the opcode for "MOV CX, immediate_word").
Actually, you probably would be better off treating the two halves of CX separately, even given the extra two cylinder bits in CL. Given what I've said here, you can see that for a disk with more than 256 cylinders, the split is rather awkward to show as a single word, as the bit wrap not to the low bits of the low word but to the high bits. for example, to read cyl 511, sector 34 of a hard disk, it would be
CL CH
76 543210 | FEDCBA98
01 100100 | 11111111
0x64 | 0xFF
which as a single number comes out to the rather enigmatic 0x0FF64. This obscures the relationship bettween them; it would be better to do something like:
Code: Select all
MOV CH, 0xFF ; 0xFF
MOV CL, 01000000b ; + (0x100 * 1) = 0x01FF
AND CL, 0x22 ; now mask sector value in
CCAW (Comments and Corrections Are Welcome).
Re:Am I stupid? (disk i/o question 2)
ok, I tried the following code, but it's still not working, I receive AH=02 error.
Maybe I made someother error...
Here is my full code (disk read )
mov ax,ds
mov es,ax - preparing ES:BX buffer
mov bx,0x0
mov ah,0x02
mov al,0x01 - 1 sec. only to read
mov dx,0x0 - drive A:, head 0
mov ch,0x0
mov cl,0x20 - track 0 sector 1
int 0x13
Where is the problem!!!?
Thank you for your patience...
Comet - Italy
Maybe I made someother error...
Here is my full code (disk read )
mov ax,ds
mov es,ax - preparing ES:BX buffer
mov bx,0x0
mov ah,0x02
mov al,0x01 - 1 sec. only to read
mov dx,0x0 - drive A:, head 0
mov ch,0x0
mov cl,0x20 - track 0 sector 1
int 0x13
Where is the problem!!!?
Thank you for your patience...
Comet - Italy