Today, the code is written to read and write floppy disk, the goal is to cross-track read and write operations into a number of single-track read and write operations. The idea is this: the first sector is located in the track of the sector read and write, and then modify the output parameters--Remove the part that has been read and write, recalculate the starting logical sector area code, the number of sectors to read and write, the memory buffer address, so that you can read and write as a new task. In order to facilitate the test, put yesterday's code together with the output text part to paste up:
; readwritefloppylogicalsectors.nas; =============================================================== =========================[section .data] icylinder dd 0 ihead dd 0 isector dd 0 nSectorsOfThisTrack dd 0 ; Number of sectors to read and write in the track where the starting sector is located nSectorsOfOpetate dd 0 ; Number of sectors actually successfully read and written strFormat db ' ibeginlogicalsector = %04d, nsectors = %02d, memory address = %04d ,clylinder = %02d, head = %02d, sector = %02d ', 0xa, 0; *************************** ; =========================================== =============================================[section .text]extern _printfglobal _readwritefloppylogicalsectors; -------------- --------------------------------------------------------------------------; function Format: int operateonetrack (int ifunctionnumber,; int iBeginLogicalSector, int Nsectors, unsigned char *puchbuffer);; function: Read/write floppy logical Sector; entry parameter:ifunctionnumber = function number:02h read, 03h write; iBeginLogicalSecot = Start logical sector area code; nSectors = number of sectors to read (all sectors that need to read and write must be within the same track); puchBuffer = memory buffer address for storing data; return value: 0 = success, other values = error status code _OPERATEONETRACK:&NBSP;&NBSP;&NBSP;&NBSP;PUSH&NBSP;EBP mov ebp, esp sub esp, 7 * 4 ; Calculate cylinder number:= logical sector area code div (number of heads * number of sectors per track) xor edx, edx mov eax, [ebp + 3 * 4] mov ebx, 36 div ebx mov [ icylinder], eax ; Calculate Magnetic number:= (logical sector area code div number of sectors per track) mod head count xor edx, edx mov eax, [ebp + 3 * 4] mov ebx, 18 div ebx xor edx, edx ; only a reserved quotient, discard the remainder mov ebx, 2 div ebx mov [ihead], edx ; Calculate sector Area code:= (logical Sector Code mod number of sectors per track) + 1 xor edx, edx mov eax, [ebp + 3 * 4] mov ebx, 18 div ebx inc edx mov [iSector], edx ; output calculation Results--The actual application must be swapped with the call int 0x13 code mov eax, [isector] push eax mov eax, [ ihead] push eax mov eax, [icylinder] push eax mov eax, [ebp + 5 * 4] &NBSP;&NBSP;&NBSP;PUSH&NBSP;EAX&NBSP;&NBSP;&NBSP;&NBSP;MOV&NBSP;EAX,&NBSP;[EBP&NBSP;+&NBSP;4&NBSP;*&NBSP;4] push Eax mov eax, [ebp + 3 * 4] push eax mov eax, strFormat push eax call _printf add esp, 7 * 4 ; return value mov bl, ah xor eax, eax mov al, bl leave ret; --- -------------------------------------------------------------------------------------; function Format:int Operatefloppylogicalsectors (int ifunctionnumber,; int Ibeginlogicalsector, int nsectors, unsigned char *puchbuffer);; function: Read/write floppy logical Sector; entry parameter:ifunctionnumber = function number:02h read, 03h write; ibeginlogicalsecot = Start logical sector area code; nsectors = Number of sectors to read and write; puchbuffer = the memory buffer address where the data is stored ; return value:eax = The number of sectors that were actually successfully read and written _READWRITEFLOPPYLOGICALSECTORS:&NBSP;&NBSP;&NBSP;&NBSP;PUSH&NBSP;EBP mov ebp, esp sub esp, 4 * 4 ; Check the validity of the parameters label_checkparameter: mov eax, [ebp + 2 * 4] ; 2 =< function No. =< 3 cmp eax, 2 jl label_return cmp eax, 3 jg Label_Return mov eax, [ebp + 3 * 4] ; 0 =< Starting logical Sector code =< 2879 cmp eax, 0 jl label_return cmp eax, 2879 jg label_return mov ebx, [ebp + 4 * 4] ; 1 =< number of sectors to read and write =< 2880 cmp ebx, 1 jl label_return cmp ebx, 2880 jg Label_Return add ebx, eax ; Starting logical sector area code + number of sectors to read and write =< 2880 cmp ebx, 2880 jg label_return mov ebx, [ebp + 5 * 4] ; Memory buffer Address &NBSP;!=&NBSP;NULL&NBSP;&NBSP;&NBSP;&NBSP;CMP&NBSP;EBX, 0 je Label_Return ; calculates the number of read/write sectors in the track where the starting sector is located xor edx, edx mov ebx, 18 ; s = ( LBA mod NS ) + 1 div ebx ; starting logical Sector area code / number of sectors per track ; remainder = starting logical sector in the sector area where the track is located - 1 sub ebx, edx ; number of sectors per track -(sector area code - 1) = ; The number of sectors (including that sector) in the track in which the starting logical sector is located, followed by that sector ; the number of read/write sectors in the track where the starting sector is located ; The number of remaining read-write sectors compared to the number of sectors to be read mov ecx, [ebp + 4 * 4] cmp ebx, ecx jl label_less_1 mov [nsectorsofthistrack], ecx ; is greater than the number of sectors to read only read and write jmp label_call_operateonetracklabel_less_1: mov [nSectorsOfThisTrack], ebx ; less than read and write all the remainder of the track ; Read and write the sectors on which the starting sector is located to read and write label_call_operateonetrack: mov Eax, [ebp + 5 * 4] push eax mov eax, [nsectorsofthistrack] push eax mov eax , [ebp + 3 * 4] push eax mov Eax, [ebp + 2 * 4] push eax call _OPerateOneTrack add esp, 4 * 4 ; operateonetrack The return value is non- 0, indicating a read-write error cmp eax, 0 jne label_return ; cumulative number of sectors successfully read/write mov eax, [nsectorsofthistrack] add [nSectorsOfOpetate], eax ; adjust each parameter value add [ebp + 3 * 4], eax ; adjust the starting logical sector area code &NBSP;&NBSP;&NBSP;&NBSP;SUB&NBSP;[EBP&NBSP;+&NBSP;4&NBSP;*&NBSP;4], eax ; adjust the number of sectors to read and write Mov ebx, 512 mul ebx add [ebp + 5 * 4], eax ; Adjust memory buffer address ; Loop Continue reading jmp Label_CheckParameterLabel_Return: mov eax, [nsectorsofopetate] leave ret; ***************************** ***********************************************************
Make a test with the C language call:
/* test.c */#include <stdio.h> #include <stdlib.h>extern int Readwritefloppylogicalsectors (int ifunctionnumber, int Ibeginlogicalsector, int nsectors, unsigned char *puchbuffer); Int main (int Argc, int argv[]) { int ifunctionnumber = 2, ibeginlogicalsector = 3, nsectors = 35, nret = 0; unsigned char *puchBuffer; puchBuffer = (unsigned char *) malloc (512 * nsectors); if (puchbuffer == null) { puts (" request memory failure \ n"); return -1; } printf (" data from the logical sector %04d %s %04d sector of a floppy disk to memory % d Place \ ibeginlogicalsector, ifunctionnumber == 2 ? "read" : "write", nsectors, puchbuffer); nret = readwritefloppylogicalsectors (Ifunctionnumber, ibeginlogicalsector, nsectors, puchbuffer) ; free (Puchbuffer); printf (" actual number of Read sectors: %d\n", nRet ); return nret == 0 ? -1 : 0;}
#MAkeFileALL: nasm-felf readwritefloppylogicalsectors.nasgcc-o Test test.c ReadWriteFloppyLogicalSectors.oCLS:del *. o *.exe
The output seems to be right:
Data from the logical sector of the floppy disk 3 read 35 sectors stored to memory 4007112
Ibeginlogicalsector = 0003, nsectors =, Memory Address = 4007112, Clylinder = xx, Head = xx, Sector = 04
Ibeginlogicalsector = 0018, nsectors =, Memory Address = 4014792, Clylinder = xx, Head =, Sector = 01
Ibeginlogicalsector = 0036, nsectors = Clylinder, Memory Address = 4024008, Sector =----
Number of actual read sectors: 35
Nineth Day, continue to read and write floppy disk