第一个宏汇编程序 7eM:YqT/#
/9K,W)h_
工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 *b$8O
Q?Y\WD
那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! [\Ks+S
gG 9e.++:
这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! {hXIP`
pZYcCc>6&
比较长啊!所以可以自动跳过。 5Oa`1?C1
;x|E}XD
.286 (eG9b pqr
.radix 16 RW?F{Jy{
data segment ;定义数据段 "<#
-#j
WeqE9@V
tR!
!Q
msg db 0dh, "Reading sector:$" |qn`z-
msg1 db 0dh, "Writing sector:$" |>Q]q
msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" :Z}d#Rbl
&pL.hM^
dsp db " $" [YGPcGw
TIs~?wb$
;DAP cJ}J4?
PacketSize db 16d; // 数据包尺寸(16字节) fku\O<1
Reserved db 0; // ==0 i
r72fSe
BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) o!\Q,
BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) pB
d_BaN
BlockNumL Dw 0,0; // 磁盘起始绝对块地址 M;96Wm
BlockNumH Dw 0,0; // 磁盘起始绝对块地址 'V*ixK8R0
\A{ [2
;定位用DAP (复位到0磁道) C9,|G7~*q
DAP0 db 16d xD:t$~
db 0 c Nhy.Z~D
dw 1 J$]-)`[G&
buff1 dw 0,0 )@IDmz>
dw 0,0,0,0 \o&\r)FX
xbN)z
X\z`S##kj
;DiskParameters sULCYiT|Hn
infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) Eeumi#$Z
falgs dw 0; WORD Flags; // 信息标志 MR) *Xh
Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 Y]u6f c
Heads DW 0; DWORD Heads; // 磁盘磁头数 FnoE\2}9
SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 \~LwlO o%R
Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 +
*O$
]Hh
SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) !4"!PrZDB
hPb erc2
cmpsect dw 0 v>p UVM
0ESxsba
msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" j56#KNAha
msgHds db 0dh,0a,"Heads:$" *an^
0
msgspt db 0dh, 0a,"SectorsPerTrack:$" Q)n6.%
V/e
msgTotal db 0d,0a, "Total Sectors:$" 56|o6-a^
msgSS db 0dh,0a, "Sector Size:$" 3U_-sMOB|
JlM0]__v
msgReadErr db 0dh,0a,"Error Reading Sectors:$" <l:c O$ m
msgWriteErr db 0dh,0a, "Error Writing Sectors:$" >
q}Ns^ .'
msgReset db 0dh,0a, "Reseting drive to Cyl 0" ^B>BA
j,]KidDWm
'=M4(h
buffer db 32768d dup(0); e[Tu.$f-
S
.KZ)
data ends ;数据段结尾 %![%wI?
ja<!_^h=At
stack segment \$g,Hgp/<
db 400 dup(?) Ih&rXQ$
stack ends PNSV?RT*pG
w$D&LA}(M
code segment ;定义代码段 *2?-6
assume cs:code ;规定cs的内容 g
`2DJi&)
assume ds:data ;规定ds的内容 v$P<:M M
assume ss:stack ^`HP&V
L.E6~Rv
start: mMz^I7$
pusha ?!uj8&yyf
cl`!A2F1G#
)1EF7.|
mov ax,data ;程序从start开始 $N}nO:`t
mov ds,ax ;ds置初值,data的段地址 by:"aDGK.
*_qW;
l7
;设置缓冲区 65 P*Gu?
lea bx, buffer rz@FUU:&
mov bufferaddr,bx ! H^,p$`[i
mov buff1,bx ( <Abw{BTm
mov bx,ds rt_k }
mov bufferaddr+2,bx o_(
@v2G`
mov buff1,bx _$Wj1h
c2tf7fkH
lea di,infosize +9tm9<F8
mov dl,80h 9{A[n}
mov ah,48h s`Y8&e.Yr
int 13h U= Gw(
-$x5[6bN
lea bx,msgcyl ']x`d
mov dx,bx I}Fv4wlZG
mov ah,09 l{2Y[&%
int 21h rryC^Vma
mov dx,cylinders
+K@wh
call dispdx T[?toqkD>z
/"f4aF[
lea bx,msghds VV$$t;R/
mov dx,bx <{z*6FM!'
mov ah,09 S4salpz
int 21h [110[i^
mov dx,heads B@8M2Pl
call dispdx }[$qn|
h@^d
Vg
lea bx,msgspt dr54D
mov dx,bx .# Jusd
mov ah,09 ^#V7\;v$G
int 21h e
hgUp =
mov dx,spt+2 &&Uc%vIN
call dispdx ~!PaBS3A
mov dx,spt l2&s4ERqSm
call dispdx *(?tf{
=k{ n! e
lea bx,msgtotal ]1^F
mov dx,bx /qKO9M5A
mov ah,09 &ody[k?'
int 21h dYEsSFB m
lea bx,sectors w@jC#E\
call dispqword LE'8R~4.<
Z [aKic
lea bx,msgss $GMva}@G`
mov dx,bx IwTAM9n
mov ah,09 `veq
/!
int 21h Wv4x^nJ
mov dx,sectorsize 68!W~%?pR
call dispdx \qo}}I>e
0-=PP@W
sbb word ptr sectors, 63d kT=KxS{
jnc subok iB1+4wa
sub word ptr sectors+2,1 #77p>zhY
jnc subok ?
}n\&|+
sub word ptr sectors+4,1 :/.SrkN(A7
jnc subok 5LkpfmR
sub word ptr sectors+6,1 qgk-[zW#
.#4;em%7
subok: k;fy8
odm!}stus
)R- e^Cb
R9!GDKts%
xor ax,ax {SQ#n@Q&$
mov blocknumL, ax L]syDn
mov blocknumL+2, ax Yp;6.\Z8[
mov blocknumL+4, ax /'ukeK+'
mov blocknumL+6, ax S,*
5, j&-{0W
startread: H2cY},
Yu`KHvur
call rwsect 2qN|<S&
8iIz!l%O
adc word ptr blocknuml,63d o)M=
; !
jnc addok -J`VXG:M
adc word ptr blocknuml+2,1 3jJd)C R
jnc addok |
)4aIa
adc word ptr blocknuml+4,1 KkCA*GS
jnc addok Gy3t
adc word ptr blocknuml+6,1 FUD
M]:XQ
jnc addok #guq/g$
,WA[HwY-
addok: Q!T+Jc9N
mov ax, word ptr sectors+6 4)DI0b"
cmp ax, blocknuml+6 WlF}R\N!
jg complete v5/2-<6x
jl startread |E(`9
mov ax, word ptr sectors+4 Cb1fTl%
cmp ax, blocknuml+4 u> @Yoyc
jg complete ]E:P-xTwaI
jl startread 4(hHp6}b
mov ax, word ptr sectors+2 9iwSE(},
cmp ax, blocknuml+2 Wifr%&t{J
jg complete p
bT sn
jl startread zYz0R:@n+
mov ax, word ptr sectors
egd%,`
cmp ax, blocknuml m,qMRcDF
jg complete
M?nYplC
jl startread QrX 5Kwq
x,+2k6Wn!
complete: ({5`C
dVi
dB=aq34l
lea bx,msgready 1c2zFBl.&
mov dx,bx xc&&UKd
mov ah,09 Y~fa=R{W
int 21 _P:}]5-|
H;=JqD8`
popa in[yrqFb7t
mov ax,3100h 9[9
ZI1*s
int 21h `nvm>u~[Hq
5>nbA8
; U7(t >/
dispdx proc near 7R{(\s\9:
pusha zQt"i`{U
lea bx, dsp+3 VOa7qnh4:[
mov cx,4 ;r1.Uz(
?S~@Ea8/M
repeat0: W,53|9b@
mov al,dl Z7Gl^4zn
and al,0fh
n;w&}g
cmp al,09h 5R UhrE
jg add40 v<Ozr:lL
add al, 30h }23#z
jmp okadd c[6=&
add40: #% 1|$V*:
add al,37h WS7a]~3'
okadd: Pi
!3wy
mov byte ptr [bx],al (pud`@D;[
dec bx Z'V"nhL
shr dx,4 zg[.Pws:E
loopnz repeat0 ,5 ylrE
lea bx,dsp ]rY3bG'&
mov dx,bx jW<aAd
mov ah,09h g(b:^_Nep
int 21h `Cv@16
?%]?#4bkc
popa =a]B#uUn
ret UEb'b,O_9
dispdx endp Cbq|<p# #o
_ft)e3Gf
dispqword proc near ;Q}pmBkqB
pusha Ed^F_Gg#
mov cx ,4 KsG>,#
Q
add bx,6 X *fle
repeatdecbx: E979qKl
mov dx,[bx] ,RYahu
call dispdx 8YLS/dN0 w
sub bx,2 c1 ~=
loopnz repeatdecbx 8K;wX%_,
popa Bt?
.8H6Y
ret &UV=<Az{
dispqword endp g:&V9