第一个宏汇编程序 ;R3o$ZlY
V=Z%y$1Bc
工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 :J+ANIRI
tv;?W=&P
那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! Z5`V\$
}s8xr>
这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! Z`n "}{
('.I)n
比较长啊!所以可以自动跳过。 ~h%H;wC&
fr8';Jm
.286 _j~y;R)
.radix 16 BU|m{YZ$
data segment ;定义数据段
vF'IK,
i6O'UzD@T
xX8c>p
msg db 0dh, "Reading sector:$" hK3Twzte
msg1 db 0dh, "Writing sector:$" MYVb !
msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" BLm}mb#/{
zv^+8h7k
dsp db " $" oq(W|
.73sY5hdTN
;DAP SE$l,Z"[*b
PacketSize db 16d; // 数据包尺寸(16字节) ?gjkgCbC
#
Reserved db 0; // ==0 !"ydl2
BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) &0{&4,
BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) W~s:SN
BlockNumL Dw 0,0; // 磁盘起始绝对块地址 ~W3t(\B'
BlockNumH Dw 0,0; // 磁盘起始绝对块地址 |
Vp
?
Mv:\T%]
;定位用DAP (复位到0磁道) ~$1g"jIw
DAP0 db 16d V-"#Kf
9
db 0 r'@7aT&_
dw 1 ghk"XJ|
buff1 dw 0,0 SXV2Y-
dw 0,0,0,0 d~T@fa
r/QI-Cf&
s,M]f,T
;DiskParameters
)[=C@U
infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) u5`b")a
falgs dw 0; WORD Flags; // 信息标志 eUD 5V
Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 WWLf'89It
Heads DW 0; DWORD Heads; // 磁盘磁头数 qr~zTBT]
E
SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 GZmfE`
Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 y"H(F,(N
SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) gmOP8.g
A>*#Nw5L
cmpsect dw 0 G+m[W
CU/Id`"tW
msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" JQW7y!Z
msgHds db 0dh,0a,"Heads:$" m=w #l>!
msgspt db 0dh, 0a,"SectorsPerTrack:$" WISK-z
msgTotal db 0d,0a, "Total Sectors:$" zJOyr"B'8
msgSS db 0dh,0a, "Sector Size:$" JYLAu4s6
^xr &E
msgReadErr db 0dh,0a,"Error Reading Sectors:$" drp< f1`l8
msgWriteErr db 0dh,0a, "Error Writing Sectors:$" ,,?XGx
msgReset db 0dh,0a, "Reseting drive to Cyl 0" B~ j3!?
&C#?&AQ
P|a|4Bb+fW
buffer db 32768d dup(0); tnq ZlS
J~N!. i
data ends ;数据段结尾 ifmX<'(9A
+Edq4QYwR
stack segment {H
3wL
db 400 dup(?) _#
&_`bZH
stack ends p#>,{
DH.CAV
code segment ;定义代码段 6f+@@=Xc
assume cs:code ;规定cs的内容 j3[kG#
assume ds:data ;规定ds的内容 8C I\NR{x8
assume ss:stack rgEN~e'
)W1[{?
start: >=3oe.$)
pusha uY3?(f#
q%XjJ -s:
+77j2W_0
mov ax,data ;程序从start开始 W^
eQ}A+Z
mov ds,ax ;ds置初值,data的段地址 C
*7x7|z
$`L
|
;设置缓冲区 +;q`A1
lea bx, buffer cxIAI=JK
mov bufferaddr,bx v}@Uc-(
mov buff1,bx p;mV?B?oAQ
mov bx,ds K
)eyFc
mov bufferaddr+2,bx k7 Ne(4P
mov buff1,bx ^Jc|d,u;s
8]4
W@~c
lea di,infosize ~e5E%bXxC
mov dl,80h
?O9|
mov ah,48h /8/N
int 13h 41+@!`z7
%)e&"
mq!|
lea bx,msgcyl HrR
w
mov dx,bx pQ8f$I#v
mov ah,09 LfvRH?<W
int 21h }3-`e3
mov dx,cylinders g c<Y?a-
call dispdx t;y@;?~
o%$R`;
lea bx,msghds cHnd
gUW]
mov dx,bx O81'i2MJ9
mov ah,09 SOS|3q_`
int 21h <JW%h :\t
mov dx,heads _iu^VK,}
call dispdx G(1_P1
V@`%k]k
lea bx,msgspt C`
8.8
mov dx,bx /K<>OyR?
mov ah,09 _A=i2?g
int 21h k:&B
b"
mov dx,spt+2 R l)g[s
call dispdx )
gxN'z
mov dx,spt "}0)~,{xB
call dispdx IYhn*
- P4X@s_;
lea bx,msgtotal -R`nitf
mov dx,bx j% '~l#nw
mov ah,09 !{A#\~,
int 21h $-39O3
lea bx,sectors UxnZA5Lk*
call dispqword :6
Gf@Z&+
i~m;Ah,#
lea bx,msgss mzf^`/NO
mov dx,bx p)~EG=p
mov ah,09 d 0:;IUG
int 21h c >xHaA:V
mov dx,sectorsize 4v`;D,dIu
call dispdx c3O&sa
V!
%~N| RSec
sbb word ptr sectors, 63d o\nFSGkn
jnc subok NHhKEx0Gtu
sub word ptr sectors+2,1 Qo80u?*
jnc subok o9Tsyjbj
sub word ptr sectors+4,1 F*y7
4j,
jnc subok JE;!~=
sub word ptr sectors+6,1 mqiCn]8G
Z_Y gV:jc
subok: E.CG
O#)YbaE
yz%o?%@
e`?o`@vO,
xor ax,ax qh6Q#s>tH
mov blocknumL, ax v/,,z+%-
mov blocknumL+2, ax 9Wdx"g52_D
mov blocknumL+4, ax l^__oam
mov blocknumL+6, ax <"7Wb"+
-hGLGF??
startread: W}WDj:
)t$-
/8
call rwsect > v4+@o[~
2hb>6Z;r]K
adc word ptr blocknuml,63d |sAl k,8s
jnc addok nDz.61$[
adc word ptr blocknuml+2,1 ZD4:'m`T/
jnc addok
~vMJ?P@
adc word ptr blocknuml+4,1 W'v
o?
jnc addok ,fhK
adc word ptr blocknuml+6,1 O
2+taB
jnc addok 1gX$U00:
nMBF/75
addok: =@d->d
mov ax, word ptr sectors+6 ]'0}fuV
cmp ax, blocknuml+6 tjcsT>
jg complete 2WB`+oWox
jl startread "l B%"}
mov ax, word ptr sectors+4 J #;|P
-pt
cmp ax, blocknuml+4 u_Xp\RJ
jg complete -s7a\H{~
jl startread @$;I%
mov ax, word ptr sectors+2 *^ua2s.
cmp ax, blocknuml+2 2xv[cpVi
jg complete t24.u+O
jl startread $/Llzpvny
mov ax, word ptr sectors j!IkU}*c
cmp ax, blocknuml QF$s([
jg complete 0
.ck!"h}
jl startread |zy` ]p9
:{aiw?1
complete: dfXBgsc6i
caL\ d
lea bx,msgready <#)Q.P
mov dx,bx TjjR% 3
mov ah,09 _DYe<f.
int 21 /LG}nY
nlc$"(eA[H
popa V"
KuwM
mov ax,3100h e8k|%m<Sp
int 21h {-hu""x>
xr31<4B
; ;/!o0:m^I
dispdx proc near ~8)l/I=`);
pusha Dt'bbX'edw
lea bx, dsp+3 bMqFrG
mov cx,4 pR!m
aoGns46Y
repeat0: +*wo iSD
mov al,dl k:z)Sw
and al,0fh *d-JAE
cmp al,09h }RUK?:lEA
jg add40
L$@qEsO
add al, 30h R3*{"!O
jmp okadd <_SdW 5BF<
add40: 9x#Tj/5%
add al,37h {@[#
0gPH
okadd: , Q )
mov byte ptr [bx],al #d$lN}8
dec bx Axla@
shr dx,4 $ou/ Fn
loopnz repeat0 9dva]$^:*1
lea bx,dsp ./CDW
mov dx,bx <jh=W9.N_
mov ah,09h :,.HJ[Vg&
int 21h !_-Uwg
F
MT
_X
popa ((6?b5[
ret yL23Nqe
dispdx endp *1*i5c
E U'P
U
dispqword proc near E=ObfN"ge
pusha q<cxmo0S
mov cx ,4 (bD#PQXzm
add bx,6 nHQWO
repeatdecbx: _CizU0S
mov dx,[bx] !HF<fn
call dispdx p & i+i
sub bx,2 %kuUQ%W1
loopnz repeatdecbx UTO$L|K
popa ;Ao`yC2(v
ret jPs{Mr<
dispqword endp 2|${2u`$&y
u&e?3qKX(
rwsect proc near 5
axt\
R=S)O.*R
lea bx,msg }wC=p>zA
mov dx,bx
u0%bv\$m
mov ah,09h ~NIqO4 D
int 21h ksyQ_4^SO
af&P;#U
lea bx,BlockNumL _TbvQY
call dispqword D&D-