第一个宏汇编程序 S2)rkX$
p8F5b8]*
工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 AF5.gk=
TL(L[
那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! iq`y
Au'[|Prr
这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! v2 [
l$
r=dFk?8XbC
比较长啊!所以可以自动跳过。 Fl GKy9k
,D-VC{lj
.286 uY;-x~Z
.radix 16 ='=\!md
data segment ;定义数据段 *ms?UFV[r
7>EjP&l
Dqu1!f
msg db 0dh, "Reading sector:$" x,"'\=|s*
msg1 db 0dh, "Writing sector:$" LQSno)OZ
msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" <{.o+~k
>S5:zz\
dsp db " $" LV{a^!f`y
z;UkK
;DAP 8Pklw^k
PacketSize db 16d; // 数据包尺寸(16字节) F9]j{'#
Reserved db 0; // ==0 dX0A(6
BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) Fs7/3
BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) [#H$@g|CT
BlockNumL Dw 0,0; // 磁盘起始绝对块地址 /OaLkENgvf
BlockNumH Dw 0,0; // 磁盘起始绝对块地址 :0pxacD"!
HUurDgRi]
;定位用DAP (复位到0磁道) D,+I)-k<
DAP0 db 16d ni gp83:
db 0 c$
Kn.<a
dw 1 :Vq gmn
buff1 dw 0,0 "V:B-q
dw 0,0,0,0 9I/o;Js
]*-9zo0
HPs$R[
;DiskParameters ulsr)Ik
infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) v`B7[B4K3
falgs dw 0; WORD Flags; // 信息标志 GE=#8-@g~p
Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 6Gjr8
Heads DW 0; DWORD Heads; // 磁盘磁头数 =rS z>l
SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 0Ha1pqR
Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 0V*L",9M
SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) O&]Y.Z9,A
'3eP<earRP
cmpsect dw 0 ^1U2&S
R,01.N( U
msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" u2'xM0nQ
msgHds db 0dh,0a,"Heads:$" $53I%.
msgspt db 0dh, 0a,"SectorsPerTrack:$" r7sPFM
msgTotal db 0d,0a, "Total Sectors:$" zEJ|;
oL
msgSS db 0dh,0a, "Sector Size:$" Dm6WSp1|
b
?lCKZm.,(-
msgReadErr db 0dh,0a,"Error Reading Sectors:$" X\\WQxj
msgWriteErr db 0dh,0a, "Error Writing Sectors:$" `':$PUz,g
msgReset db 0dh,0a, "Reseting drive to Cyl 0" D!TL~3d
1
C\UD0r'p?
$(_Xt- 6
buffer db 32768d dup(0); 0Ph,E
UT$G?D";M
data ends ;数据段结尾 <1]#
E@
5B| iBS l
stack segment 5n
zkZw
db 400 dup(?) '.oEyZA;o
stack ends Mq]~Ka3q7
HS| &["
code segment ;定义代码段 CDe
i+ q
assume cs:code ;规定cs的内容 yB(^t`)}N
assume ds:data ;规定ds的内容 [Fe`}F}Co8
assume ss:stack +r9:n(VP
j2" jCv
start: rixNz@p'%
pusha <R}(UK
<pRb#G"
6gfv7V2H
mov ax,data ;程序从start开始 Q~]#x![u0
mov ds,ax ;ds置初值,data的段地址 he&*N*of:
J=W"FEXTL7
;设置缓冲区 XbYW,a@w2
lea bx, buffer LOi5 ^Um|
mov bufferaddr,bx &| el8;D
mov buff1,bx YSk,kU
mov bx,ds mKynp
mov bufferaddr+2,bx [-_u{j
mov buff1,bx H-?SlVsf
yWu80C8q
lea di,infosize oUR'gc :
mov dl,80h ?G+v#?A
mov ah,48h 25h.u>6@{
int 13h Z2`(UbG}
$I!vQbi
lea bx,msgcyl _QfA'32S
mov dx,bx u*Eb4
mov ah,09 )El#Ks5u
int 21h k2N[B(&4J
mov dx,cylinders LX4S}QXw
call dispdx UceZWtYa
IX;u +B
lea bx,msghds HgE^#qD?
mov dx,bx -gH1`*YL
mov ah,09 9f;\fe
int 21h K~AQ) ]pJI
mov dx,heads f&B&!&gZ
call dispdx Q u2W
+LV~%?W
lea bx,msgspt r8+{HknB;
mov dx,bx /og2+!
mov ah,09 d
raY/
int 21h v"6q!
mov dx,spt+2 azz6_qk8
call dispdx |#$Wh+,*
mov dx,spt '~%1p_0dq
call dispdx P-[6xu+]
jR\&2;T
lea bx,msgtotal TIlcdpwXf
mov dx,bx F))+a&O
mov ah,09 f$9V_j-K+
int 21h Z1u{.^~ ^z
lea bx,sectors K[PIw}V$?:
call dispqword +mE y7qM
py9(z`}
lea bx,msgss He. gl
mov dx,bx rC}r99Pe:x
mov ah,09 $/nU0W
int 21h Xm*gH, '
mov dx,sectorsize }'a}s0h
call dispdx uG&xtN8
Zz=+?L
sbb word ptr sectors, 63d h djv/
jnc subok j*<H18^G
sub word ptr sectors+2,1 Hb=4k)-/]
jnc subok -?'r_t
sub word ptr sectors+4,1 *^ncb,1+i
jnc subok >}GtmnF
sub word ptr sectors+6,1 xl@l<
&V$_u#<
subok: wgpu]ooUF&
2 Q,e1'=
bNp
RGhlV
T?:Vw laE
xor ax,ax |/[?]`
mov blocknumL, ax ~\<Fq \.x
mov blocknumL+2, ax <i`Ipj
mov blocknumL+4, ax 0J z'9
mov blocknumL+6, ax v/\l
#, W7N_mt
startread: dGMBgj
HlgF%\@a+U
call rwsect i[H`u,%+(
Hq"i0Xm
adc word ptr blocknuml,63d 0RN]_z$;H
jnc addok g:`V:kbY$
adc word ptr blocknuml+2,1 C^XJE1D.
jnc addok R
@b[o7/
adc word ptr blocknuml+4,1 wqJ^tA!
jnc addok >7B6iR6N
adc word ptr blocknuml+6,1 ZJ'#XZpr
jnc addok NMM0'tY~
:84fd\It4
addok: i]a0
"
mov ax, word ptr sectors+6 ?V"X=B2
cmp ax, blocknuml+6 ?@6N EfQf
jg complete l_FttN
jl startread J7/"8S_#N
mov ax, word ptr sectors+4 SaMg)s~B
cmp ax, blocknuml+4 Q3u
P
7j
jg complete i5w
jl startread 4!,x3H'
mov ax, word ptr sectors+2 \ $}^u5Y
cmp ax, blocknuml+2 )t{?7wy
jg complete ~~,\BhG?
jl startread ?d0I*bs)7
mov ax, word ptr sectors _5EM <Ux
cmp ax, blocknuml lNowH0K!D
jg complete yYwZZa1
jl startread j8W
nXp_
4*d$o=wa
complete: qk{2%,u$@{
v4=9T<[
lea bx,msgready Z{xm(^'i
mov dx,bx 3qE2mYK
mov ah,09 rg)>ZHx
int 21 ,]\L\ V
nAG2!2_8
popa AK%`EsI^
mov ax,3100h $(K[W}
int 21h u;H SX
,IF3VE&r
; lX/s
Q
dispdx proc near CWdA8)n.
pusha s"?Z jV)`
lea bx, dsp+3 q+5g+9
mov cx,4 iyAeR!`
ob05:D_bc9
repeat0: K[PH#dF5,x
mov al,dl @v\Osp t=
and al,0fh 0#0[E ,
cmp al,09h R$k4}p
jg add40 thIuK V{CO
add al, 30h py VTA1
jmp okadd W~2`o*\l
add40: >VM@9Cph
add al,37h D/^yAfI
okadd: /]=Ih
mov byte ptr [bx],al 4UT%z}[!
dec bx kL\
FY
shr dx,4 A}?n.MAX>
loopnz repeat0 ;D&FZ|`(u
lea bx,dsp FM$XMD0=
mov dx,bx O{SP4|0JV
mov ah,09h +KgLe> -}
int 21h W0J d2 *]
pSvRyb.K
popa @{3$H^
ret 0sM{yGu=,
dispdx endp b(+M/O>I
=v]\{.
dispqword proc near =7wI/5iN
pusha 109dB$+$
mov cx ,4 <]xG
d!x$
add bx,6 F=!p7msRB
repeatdecbx: 9`VgD<?v
mov dx,[bx] }m0*w3
call dispdx |N/Grk4
sub bx,2 P~`gWGC}
loopnz repeatdecbx
{fFZ%$
popa | s%--W
ret 1`J-|eH=Q
dispqword endp j\k|5="w-
s9+Rq*Qd
rwsect proc near w$8Su:g=
uMKO^D
lea bx,msg u:JD
mov dx,bx jcD_<WSe
mov ah,09h I },.U&r
int 21h e=&,jg?K
ej,j1iB
lea bx,BlockNumL `dekaRo
call dispqword 88x_}M^Fnl
}vzP\
lea di, packetsize n4\UoKq
mov dl,80h 1Kszpt(Ld
mov ah,42h ~o_0RB
int 13h o.W:R Ux
jnc readok rT7W_[&P
,|6O}E&
mov cx,5 s:ig;zb
;出错后重试(定位0道后再重读) lHQ:LI
retryrd: k%Dpy2uH
lea bx, msgReadErr ^=`7]E [p
mov dx,bx 67/J sL
mov ah,09 ea[vzD]
int 21h x`~YTOfYk
Z>
Jm
@a2n{
lea di,dap0 l*~O;do
mov dl,80h s)C5u;3!
mov ah,44h 4
Bg"b/kF
int 13h dJxdrs
F3+
;2GG2
lea bx,BlockNumL 1c8Nr&Jl
call dispqword UgI0
*PE2
Yw @)0%G
lea di, packetsize UtPFkase
mov dl,80h " O0p.o
mov ah,42h 9'+Eu)l:
int 13h uqy&PS
jnc readok 3}R}|Ha
J#
loopnz retryrd ._'AJhU$0
NV\t%
/ ?
readok: v6=pV4k9
lea di, packetsize l7#5
.%A
mov dl,80h ehCGu(=
mov ah,43h Pt< JF
int 13h -i93
Cge@A'
2
rwsect endp 8p D$/
Rr#Zcs!G
code ends ;代码段结尾 G#yv$LY#
end start ;结束汇编 m#6RJbEz
QL/I/EgqC