第一个宏汇编程序 g'Id31r'
Hswgv$n
工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 4\?GA`@
U}]uPvu
那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! Ov5*&*P
Om/mpU/U
这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! SA'c}gP
B<A=U r
比较长啊!所以可以自动跳过。 61}hB>TT:
$sTvXf:g
.286 *?Pbk+}%
.radix 16 ^9zFAY.|
data segment ;定义数据段 5 Y|(i1
$!-a)U,w$B
1}$GVb%i
msg db 0dh, "Reading sector:$" k"V@9q;*
msg1 db 0dh, "Writing sector:$" 4qc0Q
A%
msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" M^$liS.D
/cN. -lEo%
dsp db " $" z#|#Cq`VG
]*Tnu98G}
;DAP mn;Wqb/
PacketSize db 16d; // 数据包尺寸(16字节) Q:+cLl&;hB
Reserved db 0; // ==0 1D pRm(
BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) R
Wd#)3
BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) ZvS|a~jO
BlockNumL Dw 0,0; // 磁盘起始绝对块地址 vMQvq9T}
BlockNumH Dw 0,0; // 磁盘起始绝对块地址 nU6WT |
Q5N;MpJ-
;定位用DAP (复位到0磁道) @A-^~LoP.
DAP0 db 16d TP5?%SlJ
db 0 \EC=#E(
dw 1 pJK}9p=4`
buff1 dw 0,0 Gw;[maM!%`
dw 0,0,0,0 3X,SCG
v G7aT
yye(^
;DiskParameters \s[/{3
infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) o9Z!Z^
falgs dw 0; WORD Flags; // 信息标志 M-B -
Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 tl uyx
Heads DW 0; DWORD Heads; // 磁盘磁头数 ZMVQo-=
SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 G \S >H
Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 ).Ei:/*j
SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) {m&8Viq1
3V"y|q
cmpsect dw 0 ~D9VjXfL)
J:c]z
9&!
msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" t#
p*{S 3u
msgHds db 0dh,0a,"Heads:$" \AT]$`8@_
msgspt db 0dh, 0a,"SectorsPerTrack:$" )/:&i<Q:
msgTotal db 0d,0a, "Total Sectors:$" -'sn0_q/e
msgSS db 0dh,0a, "Sector Size:$" nO d'$q
H3?HQ>&O7
msgReadErr db 0dh,0a,"Error Reading Sectors:$" 6}RRrYL7I
msgWriteErr db 0dh,0a, "Error Writing Sectors:$" Yp_R+a^
msgReset db 0dh,0a, "Reseting drive to Cyl 0" qC%[J:RwF
xTJ-v/t3<
M_4:~&N$
buffer db 32768d dup(0); Nd"Rt
njk1x
data ends ;数据段结尾 WG_20Jd
JY
p=U/l#xO
stack segment xGzp}
db 400 dup(?) A|D]e)/6+B
stack ends cVR3_e{&H
LD~s@}yH>
code segment ;定义代码段 _v+mjDdQ
assume cs:code ;规定cs的内容 aC&ZV}8of
assume ds:data ;规定ds的内容 PUdJ>U
assume ss:stack .kGlUb?^Q
*FwHZ
Z~U
start: x*9CK8o=
pusha 3>`CZ]ip}
Ifc}=:nr
AxN.k
mov ax,data ;程序从start开始 Y\qiYra
mov ds,ax ;ds置初值,data的段地址 Snh
B$DG
x 7;Zwd
;设置缓冲区 4rh*&'
lea bx, buffer QqC4g]
mov bufferaddr,bx bYKyR}e
mov buff1,bx DM-8azq $
mov bx,ds (j%d{y4
mov bufferaddr+2,bx CulU?-[i
mov buff1,bx % 1+\N
\I"UW1)B
lea di,infosize p:hzLat~
mov dl,80h S!<1CFh
mov ah,48h 8%$Vj
int 13h
1Ugyjjlz
ww]^H$In
lea bx,msgcyl Cyb-}l
mov dx,bx YGA("<
mov ah,09 CFW\
int 21h C XQPbt[5
mov dx,cylinders ::xH C4tw
call dispdx w
:w
2ja@NT
lea bx,msghds >tq,F"2amC
mov dx,bx xz+Y 1fYT
mov ah,09 u7e g:0Y
int 21h CTbz?Kn
mov dx,heads A-GRuC
call dispdx b Hr2LhQCN
NjCdkT&g
lea bx,msgspt T/_JXK>W
mov dx,bx M@>EZ
mov ah,09 zKi5e+\
int 21h >t/P^fr_F
mov dx,spt+2 ohdWEU,
call dispdx Kzs
]+Cl
mov dx,spt z_dorDF8`>
call dispdx fC2
',MiD=_
lea bx,msgtotal 3q>6gaTv
mov dx,bx |vZ\tQ
mov ah,09 vFK&6
3
int 21h L29,Y=n@
lea bx,sectors uF!3a$4]
call dispqword o|s JTY
hm%'k~
lea bx,msgss pX:FXzYQ
mov dx,bx .Z!!x
mov ah,09 OZF^w[ `w
int 21h r3@Q(Rb
mov dx,sectorsize %G<!&E!0h
call dispdx j;tT SNF
K8`M~P.
sbb word ptr sectors, 63d +P7A`{Ae
jnc subok J{gqm
sub word ptr sectors+2,1 3sk$B%a>Z
jnc subok ;BEg"cm
sub word ptr sectors+4,1 4DVkycM
jnc subok (;V=A4F-D
sub word ptr sectors+6,1 xb!h?F&
b"ypS7
_
subok: ?,J
N?
<bwsK,C
u7=jtB
8QeM6;^/5
xor ax,ax {QTrH-C
mov blocknumL, ax H:X=v+W
mov blocknumL+2, ax *nB fF{y
mov blocknumL+4, ax wo>srZs
mov blocknumL+6, ax U8Pnt|0 M
IeqJ>t:
startread: !OJ@
=y`i
]U]22I'+$2
call rwsect -$(,&qyk
3gW4\2|T
adc word ptr blocknuml,63d [mSK!Y@u
jnc addok ({ 7t
p!@
adc word ptr blocknuml+2,1 N#;k;Z'iL
jnc addok i>9/vwe
adc word ptr blocknuml+4,1 y&0&K4aa
jnc addok y@;4F n/
adc word ptr blocknuml+6,1 oRM,_
jnc addok #rZk&q
LF'M!C9|
addok: B/i`
mov ax, word ptr sectors+6 yqF$J"=|
cmp ax, blocknuml+6 wl{Fx+<^3
jg complete 6?/$K{AI
jl startread JTw'ecFev
mov ax, word ptr sectors+4 ?"p:6%GFz
cmp ax, blocknuml+4 8t$a8 PE
jg complete S8O^^jJq;
jl startread }}3*tn<6
mov ax, word ptr sectors+2 5q`d=
L,
cmp ax, blocknuml+2 T,72I
jg complete Vrf+~KO7
jl startread ^|6%~jkD5
mov ax, word ptr sectors +e0]Y8J{
cmp ax, blocknuml kO:iA0KUX
jg complete e&C(IEZ/N;
jl startread u"K-mr#$[o
-R,[/7zj
complete: 4]N`pD5
O[3AI^2
lea bx,msgready n%w36_
mov dx,bx [?<"SJ,`
mov ah,09 um@RaU
int 21 .,:700n+^
x@F"ZiYD@O
popa A#W%ud4
mov ax,3100h b9[KdVsT6^
int 21h @L%9NqE`O
GNXQD}L?b?
; TqNEU<S/t
dispdx proc near M%wj6!5
pusha ,w|f*L$
lea bx, dsp+3 wSp1ChS k
mov cx,4 *M_.>".P
k;p:P ?s5Y
repeat0: krTH<- P
mov al,dl ,.`";='o
and al,0fh X[8m76/V
cmp al,09h (Al.hEs'
jg add40 4-`C !q
add al, 30h
<^&NA<2
jmp okadd DRD%pm(
add40: DT # 1*&-
add al,37h &0O1tM*v
okadd:
l1~>{:mq
mov byte ptr [bx],al G?)vqmJ%
dec bx 1\7SiQ-
shr dx,4 eR(PY{
loopnz repeat0 +[9~ta|j
lea bx,dsp oy!W$ ?6
mov dx,bx ]
6{G;f$
mov ah,09h . `lcxC
int 21h "v-\nAu
I"E5XVC);
popa LSQ2pB2V
ret im^G
{3z
dispdx endp WigC'
tr2@{xb
dispqword proc near vrsO]ctI
pusha #F5O>9hA
mov cx ,4 t_&FK A
add bx,6 uXuMt
a*Y
repeatdecbx: }%EQ
mov dx,[bx] >2gemTy
call dispdx +XU*NAD,!
sub bx,2 M:OY8=V
loopnz repeatdecbx n
5NkjhP~Z
popa [{_JO+)+n
ret dL<okw
dispqword endp QQKvy0?1
06I'#:]
rwsect proc near 1Y410-.3w{
E9 QA<w
lea bx,msg fmH$1C<
mov dx,bx x%ZjGDF m
mov ah,09h \GeUX<Fl
int 21h KIdlndGs
8#S|jBV
lea bx,BlockNumL 5gg_c?Vh/
call dispqword tFvti5
H~+D2A
lea di, packetsize TL+a_]3@
mov dl,80h 0-EhDGa]r
mov ah,42h __""!Yz
int 13h lY_E=K]
jnc readok F;jl0)fBR=
TuphCu+Oh
mov cx,5 XpWqL9s_E
;出错后重试(定位0道后再重读) ~130"WQ;
retryrd: {4&G\2<^^
lea bx, msgReadErr g% :Q86u
mov dx,bx F]3iL^v
mov ah,09 E7+y
W
int 21h Wx"bW ICc
7t\W{y
yqqP7
lea di,dap0 p"/1Kwqx
mov dl,80h ]%(hZZ
mov ah,44h ;$(a+?
int 13h /reSU 2
3|RfX
lea bx,BlockNumL Q"CZ}B1<
call dispqword 6q?C"\_
^;GJ7y&,d
lea di, packetsize ):eX*
mov dl,80h |_aE~_
mov ah,42h &|xN=U/
int 13h St/Hv[H'[E
jnc readok eKpH|S!xU
loopnz retryrd zbP0!
RNuOwZ1m
readok: I ms?^`N
lea di, packetsize
,U2
/J
mov dl,80h 3a9Oj'd1M
mov ah,43h o"t+G/M
int 13h lyKV^7}
cS,(HLO91
rwsect endp RX:\@c&
GiB3.%R`
code ends ;代码段结尾 +o)S.a+7
end start ;结束汇编 N(Us 9
E0}`+x