Практика №5
Задание: написать программу тестирования НГМД тестом «бабочка» с записью – чтением со сравнением.
Текст программы:
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
unsigned char headNum = 0;
unsigned char sectNum = 0;
unsigned char trckNum = 0;
unsigned char buffer_const[512]={0};
unsigned char buffer_const_cmp[512]={0};
unsigned char buffer_sector[512]={0};
void read_the_sector(unsigned char h, unsigned char c, unsigned char s, unsigned char sector_for_read[512]) {
int segm = FP_SEG(sector_for_read);
int offs = FP_OFF(sector_for_read);
unsigned char res = 0;
asm {
mov ah, 02h
mov al, 01h
mov dl, 00h
mov dh, h
mov cl, s
mov ch, c
mov es, segm
mov bx, offs
int 13h
pushf
pop ax
and ax, 1
mov res, al
}
if (res) {
printf("R: H (%d), C (%d), S (%d): ERROR\n", h, c, s);
}
}
void write_the_sector(unsigned char h, unsigned char c, unsigned char s, unsigned char sector_for_write[512]) {
int segm = FP_SEG(sector_for_write);
int offs = FP_OFF(sector_for_write);
unsigned char res = 0;
asm {
mov ah, 03h
mov al, 01h
mov dl, 00h
mov dh, h
mov cl, s
mov ch, c
mov es, segm
mov bx, offs
int 13h
pushf
pop ax
and ax, 1
mov res, al
}
if (res) {
printf("W: H (%d), C (%d), S (%d): ERROR\n", h, c, s);
}
}
void check_sector(unsigned char h, unsigned char c, unsigned char s) {
read_the_sector(h, c, s, buffer_sector);
write_the_sector(h, c, s, buffer_const);
read_the_sector(h, c, s, buffer_const_cmp);
write_the_sector(h, c, s, buffer_sector);
for (int i = 0; i < 512; i++) {
if (buffer_const[i] != buffer_const_cmp[i]) {
printf("X: H (%d), C (%d), S (%d): ERROR\n", h, c, s);
break;
}
}
}
int main(void) {
// check for ready
asm {
mov ah, 10h
mov dl, 00h
int 13h
// get number of heads, cylynders per head and sectors per cylinder
mov ah, 08h
mov dl, 00h
int 13h
inc dh
inc ch
mov headNum, dh
mov sectNum, cl
mov trckNum, ch
}
printf("Headers : %d\n", headNum);
printf("Cylinders per head : %d\n", trckNum);
printf("Sectors per cylinder: %d\n", sectNum);
// filling constants buffer
for (int i = 0; i < 512; i++) {
buffer_const[i] = rand()%255;
}
struct time t, start, end;
int start_time, end_time;
gettime(&start);
start_time = start.ti_sec + start.ti_min*60;
for (int head = 0; head < headNum; head++) {
for (int cyl = trckNum/2; cyl >= 0; cyl--) {
int cylTmp = trckNum/2 + cyl;
if (cylTmp != 80) {
for (int sec = sectNum/2; sec >= 0; sec--) {
if ((sectNum/2) + sec != 18)
check_sector(head, cylTmp, (sectNum/2) + sec + 1);
check_sector(head, cylTmp, (sectNum/2) - sec + 1);
}
}
cylTmp = trckNum/2 - cyl;
for (int sec = sectNum/2; sec >= 0; sec--) {
if ((sectNum/2) + sec != 18)
check_sector(head, cylTmp, (sectNum/2) + sec + 1);
check_sector(head, cylTmp, (sectNum/2) - sec + 1);
}
}
}
gettime(&end);
end_time = end.ti_sec + end.ti_min*60;
printf("Total Time is: %d s\n", end_time - start_time);
return 0;
}
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.