I made this assembly code:
Code: Select all
;-----------------------------------Disk Start-----------------------------------------;
global _readd
global _writed
;--------------------------------Read Disk Start---------------------------------------;
_readd:
;push eax
;push ebx
;push ecx
;push edx
push ebp
mov ebp, esp
mov eax, [ebp+8] ;first parameter
mov ecx, eax
cmp ecx, 256
jg short _readsector_fail
jne short _readsector
xor ecx, ecx
_readsector:
mov ebx, ecx
mov eax, [ebp+12] ;second parameter
cmp eax, 0
je _readsector_fail
push eax ;sector number
mov dx, 0x1f2
mov al, cl
out dx, al
inc dx ;dx = 0x1f3
pop eax
out dx, al
inc dx ;dx = 0x1f4
shr eax, 8
out dx, al
inc dx ;dx = 0x1f5
shr eax, 8
out dx, al
inc dx ;dx = 0x1f6
shr eax, 8
and al, 00001111b
or al, 01000000b
out dx, al
inc dx ;dx = 0x1f7
mov al, 0x20
out dx, al
mov ecx, 4
_readsector_wait:
in al, dx
test al, 0x80 ; BSY
jne _readsector_retry
test al, 0x08 ; DRQ
jne _readsector_ready
_readsector_retry:
dec ecx
jg _readsector_wait
_readsector_nextsector:
in al, dx
test al, 0x80
jne _readsector_nextsector
test al, 0x21
jne _readsector_fail
_readsector_ready:
sub dx, 7 ;0x1f0
mov ecx, 256
rep insw
add dx, 7
in al, dx ;wait 400 ns
in al, dx
in al, dx
in al, dx
dec ebx
jg _readsector_nextsector
;mov eax, edi
;cmp eax, 0x0ffffffff
;jz _readsector_fail
mov [ebp-8], edi ;Second local variable
leave
ret
_readsector_fail:
xor eax, eax
leave
ret
;-----------------------Read Disk End-------------------------------------;
In this same file I have writedisk and I mov esi, [ebp-4] (which is the first local variable).