第一个宏汇编程序
~A6 "sb=
_@Y"$V]=Vt
工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 ?a
S%
/ /'Tck
那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! A]7<'e
l=
{9L 5Q
这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! ?AEd(_a!q
*myG"@P4hW
比较长啊!所以可以自动跳过。 ]<1HM"D
nSS>\$
.286 # kyl?E
.radix 16 c! @F
data segment ;定义数据段 h;-a`@rO ;
gw"~RV0
zbNA\.y
msg db 0dh, "Reading sector:$" _5mc('
msg1 db 0dh, "Writing sector:$" g& k58{e
msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" eqq`TT#Z
|'tW=
dsp db " $" !=3Rg-'d1
F!JJ6d53y
;DAP L'lF/qe^
PacketSize db 16d; // 数据包尺寸(16字节) jk$86ma!
Reserved db 0; // ==0 7|YN:7iA
BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) zrs<#8!Y_!
BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) oK2pM18
BlockNumL Dw 0,0; // 磁盘起始绝对块地址 $(ewk):
BlockNumH Dw 0,0; // 磁盘起始绝对块地址 9qKzS<"h
bp#:UUO%S
;定位用DAP (复位到0磁道) 0n.S,3|
DAP0 db 16d `-_N@E1'>
db 0 9M_(He
-
dw 1 baee?6
buff1 dw 0,0
|g%mP1O
dw 0,0,0,0 6SVqRD<`
` @8`qXg
f/,tgA
;DiskParameters EM@;3.IO
infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) Ur^j$B}
falgs dw 0; WORD Flags; // 信息标志 '0:i<`qv#g
Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 -T7xK/
Heads DW 0; DWORD Heads; // 磁盘磁头数 'B_\TU0
O
SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 TI=h_%mO
Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 9Y/L?km_(
SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) 1~J5uB 4
in<}fAro6
cmpsect dw 0 ZPHXzi3j
5!Bktgk.
msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" )t
:7_M3
msgHds db 0dh,0a,"Heads:$" 5o#Yt
msgspt db 0dh, 0a,"SectorsPerTrack:$" n 6{2]&sd
msgTotal db 0d,0a, "Total Sectors:$" _d@=nK)
msgSS db 0dh,0a, "Sector Size:$" rz%<AF Z
Y>BP?l
msgReadErr db 0dh,0a,"Error Reading Sectors:$" ZQ3_y $
msgWriteErr db 0dh,0a, "Error Writing Sectors:$" JWROYED
msgReset db 0dh,0a, "Reseting drive to Cyl 0" 6-B 9na
{^5?)/<
Q.+|xwz
buffer db 32768d dup(0); q@n^
ZzTx
m
#f{]+6U
data ends ;数据段结尾 mffIf1f
- hzjV|
stack segment -I":
Z2.fR
db 400 dup(?) &-%X:~|:X
stack ends 6 {}JbRNf
4,G w#@
code segment ;定义代码段 Y#
FO5O%W
assume cs:code ;规定cs的内容 Tv5g`/e=Ej
assume ds:data ;规定ds的内容 ub
Y
G
assume ss:stack Tr& }$kird
;
dd Q/
start: N
L'R\R
pusha \hlR]m!C
`Gd$:qV
Rrg8{DZhv
mov ax,data ;程序从start开始 '7*=`q{
mov ds,ax ;ds置初值,data的段地址 [iS,#w`
5
iEIg:
;设置缓冲区 w%dL8k
lea bx, buffer Sw8kIC
mov bufferaddr,bx I;7nb4]AmF
mov buff1,bx y,=du
mov bx,ds
w\w(U
mov bufferaddr+2,bx >xu[q\:"
mov buff1,bx :m'+tGs
k6"KB
lea di,infosize A5fwAB
mov dl,80h u3J?bR
mov ah,48h "CQw/qZw
int 13h k%P;w1
MgJ36zM
lea bx,msgcyl -h#mn2U~3r
mov dx,bx w8iR|TV
mov ah,09 +Llo81j&
int 21h >O7~h[FN
mov dx,cylinders C5W>W4EM
call dispdx 6_gnEve
h
JN'cXZJPn
lea bx,msghds Vw#{C>
mov dx,bx ; |L
<:x/
mov ah,09 w~Ff%p@9
int 21h WKmbNvN^
mov dx,heads |E@djosyC
call dispdx V-!"%fO.s
Xf
d*D
lea bx,msgspt Sm-wH^~KA
mov dx,bx 4 =Gph
mov ah,09 -?6MU~"GK
int 21h 5,pS
g
mov dx,spt+2 l&$$w!n0w
call dispdx U47}QDh
mov dx,spt e-5?p~>
call dispdx 8' K0L(3[
^V3v{>D>
lea bx,msgtotal
npp[@*~
mov dx,bx }P9Ap3?
mov ah,09 d2S
~)/@S
int 21h `zpbnxOL$T
lea bx,sectors .>pgU{C
`!
call dispqword ]"~51HQZ
UsQ4~e 4-
lea bx,msgss 8FkFM^\1L
mov dx,bx w
$|l{VI
mov ah,09 (k`{*!:1a
int 21h Xm1[V&
mov dx,sectorsize LfLFu9#:w
call dispdx >T jJA#
is?2DcSl5
sbb word ptr sectors, 63d B[5r|d'
jnc subok [xb]Wf
sub word ptr sectors+2,1 S/ [E8T"
jnc subok X|DO~{-au
sub word ptr sectors+4,1 %ZP+zhn}
jnc subok #~L h#
sub word ptr sectors+6,1 /mM2
M-
J*fBZ.NO
subok: 4~
z?"
?!VIS>C(
&<pKx!
Pw0Ci
xor ax,ax 3WY$WRv
mov blocknumL, ax <3okiV=ox
mov blocknumL+2, ax aqU'
T
mov blocknumL+4, ax ,8MLoZ
_
mov blocknumL+6, ax |=a}iU8
\5)h tL1F
startread: jJZgK$5+
BxK^?b[E8
call rwsect ]i*](UQ
sZ&G%o
adc word ptr blocknuml,63d ww
k
P F
jnc addok fyWO
adc word ptr blocknuml+2,1 os lJC$cy'
jnc addok Zm
ogM7B
adc word ptr blocknuml+4,1 SP]IUdE\
jnc addok q2rUbU_A(
adc word ptr blocknuml+6,1 wJ<Oo@snm
jnc addok L,,*gK
vhuw&.\
addok: l8h&|RY[
mov ax, word ptr sectors+6 zTbVp8\pI
cmp ax, blocknuml+6 D]s]"QQ8
jg complete ,Gk}"w
jl startread 6t'l(E +
mov ax, word ptr sectors+4 ,)!u)wz
cmp ax, blocknuml+4 2[fN\e{
jg complete {yA$V0`N{
jl startread
j2l55@
mov ax, word ptr sectors+2 HO)/dZNU
cmp ax, blocknuml+2 k0-G$|QgIp
jg complete 6
sxffJt
jl startread 7OCwG~_^
mov ax, word ptr sectors q my%J
cmp ax, blocknuml $,>@o=)_
jg complete Mwp$
jl startread ,m<H-gwa
3q:n'PC)C
complete: B[4pX
+f
K+=+?~
lea bx,msgready 'CZa3ux
mov dx,bx %ir:ASk
mov ah,09 X>YsQrK(ig
int 21 YW\0k5[
J?UQJ&!@O
popa X[gn+6WB%
mov ax,3100h RP5+d
int 21h 41a.#o
mo{MR:>
)
; gb=/#G0R
dispdx proc near `#-P[q<v-
pusha `(6r3f~XJ
lea bx, dsp+3 F0vM0e-
mov cx,4 CzCQFqXI
^YdcAHjK
repeat0: :!a2]-D}
mov al,dl '})0!g<Y
and al,0fh 4_ v]O
cmp al,09h ?E%ELs_Dl
jg add40 xM[Vc
add al, 30h C:8_m1Y{
jmp okadd P +"Y
add40: 2`GE
add al,37h b1XRC`Gy
okadd: #@@Mxr'F
mov byte ptr [bx],al S& #U!#@
dec bx .`<@m]m-
shr dx,4 vsWHk7 9
loopnz repeat0 &UCsBqI
Y
lea bx,dsp )Or.;
mov dx,bx .\0
isO
mov ah,09h D?yG+%&9
int 21h >odbOi+X
hI?sOR!
popa %1 vsN-O}8
ret )}vNOE?X~
dispdx endp A\_ |un%
Vm}%ttTC
dispqword proc near vDl- "!G1
pusha bwM@/g%DL
mov cx ,4 +ISz?~8
add bx,6 dz
[!-M
repeatdecbx: Io4(f
mov dx,[bx] OA/WtQ5
call dispdx m'\ 2:mDu0
sub bx,2
~=<}\a~
loopnz repeatdecbx $D
v\
e
popa l
{jmlT
ret r;L>.wl*I
dispqword endp R" )bDy?
h_1T,f(
rwsect proc near 2&c9q5.b
'I;!pUfVp
lea bx,msg uXDq~`S
mov dx,bx )*; zW!H
mov ah,09h ]lw|pvtd
int 21h '0y9M
XRT
!zj0/Q G\
lea bx,BlockNumL VvFC -r,=G
call dispqword \)K^=jM
0;4t&v7
lea di, packetsize VhjM>(
mov dl,80h #_Z$2L"U
mov ah,42h "8^5>EJ
Wv
int 13h r:&`$8$
jnc readok / N)W2
)[mwP.T=
mov cx,5 :ISMPe3'
;出错后重试(定位0道后再重读) b^D$jY
retryrd: P`s
lea bx, msgReadErr -[U1]R
mov dx,bx \<}&&SuH
mov ah,09 kr$b^"Ku
int 21h x8\A<(G_M=
ydw)mT44K
D`J6h,=2l/
lea di,dap0 ?pgG,=?
mov dl,80h {u1V|q
mov ah,44h ;S0Kh"A
int 13h +aF}oA&X[
[.RO'>2z
lea bx,BlockNumL }ENR{vz$A
call dispqword 7\*FEjRM]
{
-|{xBd
lea di, packetsize P =3RLL<l
mov dl,80h
PP:(EN1
mov ah,42h X#3et'
int 13h ?(*t@
{k
jnc readok ?bM_q_5
loopnz retryrd h~{aGo
l]~n3
IK"
readok: c wg
!j!l
lea di, packetsize K=!Bh*
mov dl,80h n,$IfC"
mov ah,43h pdJ/&ufh
int 13h A
)%A!
lWBb4 !l
rwsect endp ?
4H i-
bAKiq}xG%i
code ends ;代码段结尾 2
I*;A5$N1
end start ;结束汇编 MlLb|!,)T
Bs?7:kN(