显示用户信息
UID: 231
精华:
8
发帖: 11180
财富: 1809 湾区元
威望: 3532 点
支持度: 34 点
好评度: 21 点
在线时间: 319(时)
注册时间: 2017-06-04
最后登录: 2024-09-17
|
第一个宏汇编程序 |nQfgl=V wiN0|h>, 工作后不久,单位里我所在的小组有了一台浪潮0520(XT兼容机),有了硬盘,有了汇编编译程序,就开始玩汇编了。当然那时的主要工作是用dBASEIII,这个我已经在读研期间自学会了,读了一本关于dBASEIII plus的英文书,编个dBASE/FoxBASE程序已经是小菜一碟了。 H:
(B^uH p.W7>o,[w 那时候的硬盘老出点问题,经常碰上个“Error reading data....” 啥的小毛病,但是换又不方便而且很贵。PCTOOLS与NORTON DISKEDIT扫描盘比较慢。我就自己写了一个磁盘扫描程序。算是用汇编写的第一个正式的有点用处的程序吧! ;dzy5o3 |P5dv>tb
F 这也是我现在电脑里唯一一个汇编语言的程序了,其它都随着磁盘来回更换丢了。所以,还是在老大这里存一份留个纪念吧! P#A,(Bke3 !`{?qQ[= 比较长啊!所以可以自动跳过。 *Dg@fxCQ N?@^BZ
.286 tb&?BCp .radix 16 >|SIqB<%: data segment ;定义数据段 d'_q9uf' 31G:[;g d8wGXNd7B msg db 0dh, "Reading sector:$" $wM..ee msg1 db 0dh, "Writing sector:$" Exwd,2> msgready db 0dh,0a,0dh,0a,"Reading/Writing completed!", 0dh,0a, "$" H9T~7e+ /4r2B.91O dsp db " $" k[x-O?$O@ #ZZe*B!s_ ;DAP q'jOI_b PacketSize db 16d; // 数据包尺寸(16字节) )la3GT*1mS Reserved db 0; // ==0 1GN^uia7 BlockCount dw 63d; // 要传输的数据块个数(以扇区为单位) {-5)nS^_ BufferAddr dw 0,0 ; // 传输缓冲地址(segment:offset) ]t0o%w BlockNumL Dw 0,0; // 磁盘起始绝对块地址 :BxO6@>X
c BlockNumH Dw 0,0; // 磁盘起始绝对块地址 W et0qt] uc,>VzdB ;定位用DAP (复位到0磁道) BwHJr(n DAP0 db 16d ?T/4
= db 0 LDg9@esi dw 1 ,kJ'_mq buff1 dw 0,0 s\d3u`G dw 0,0,0,0 B!&5*f}* P@O_MT .BPd06y ;DiskParameters n{QyqI infosize dw 26d; WORD InfoSize; // 数据包尺寸 (26 字节) K28L(4 ) falgs dw 0; WORD Flags; // 信息标志 mlByE,S2E Cylinders DW 0; DWORD Cylinders; // 磁盘柱面数 V[.{cY?6 Heads DW 0; DWORD Heads; // 磁盘磁头数 P`
Zon SPT Dw 0,0; DWORD SectorsPerTrack; // 每磁道扇区数 |<{SSA Sectors Dw 0,0,0,0; QWORD Sectors; // 磁盘总扇区数 sV"tN2W@ SectorSize DW 0; WORD SectorSize; // 扇区尺寸 (以字节为单位) ika*w +C`!4v\n cmpsect dw 0 >v,X:B?+FL 0N1t.3U msgcyl db 0dh,0a,"Disk Parameters",0dh,0a,"Total Cylinders:$" m'2F#{ msgHds db 0dh,0a,"Heads:$" 29:2Xu i msgspt db 0dh, 0a,"SectorsPerTrack:$" 8O^x~[sQ msgTotal db 0d,0a, "Total Sectors:$" ["nWIs[h msgSS db 0dh,0a, "Sector Size:$" |Y"XxM9 mu
B Y msgReadErr db 0dh,0a,"Error Reading Sectors:$" ?c8~VQaQ msgWriteErr db 0dh,0a, "Error Writing Sectors:$" j([b)k= msgReset db 0dh,0a, "Reseting drive to Cyl 0" |lLe^FM I!/EQO| IgbuMEfL buffer db 32768d dup(0); M{L<aYe 9':Ipf&x data ends ;数据段结尾 [],[LkS 7#)k-S!B stack segment R6<'J?k db 400 dup(?) rai'x/Ut}+ stack ends P"7` :a 6Jgl"Jw8 code segment ;定义代码段 |co#X8J assume cs:code ;规定cs的内容 ?,VpZ%Df2 assume ds:data ;规定ds的内容
8J,^O04< assume ss:stack _&=`vv' B>i%:[-e start: Apu-9|oP pusha V_
6K ?~j S[[email protected] gxhp7c182 mov ax,data ;程序从start开始 Gm-
"?4( mov ds,ax ;ds置初值,data的段地址 qBk[Afjgz 6O/ L~Z*t ;设置缓冲区 ,i*rHMe lea bx, buffer cs2-jbRn mov bufferaddr,bx <~|
n}& mov buff1,bx xiW}P% bf mov bx,ds S:!5|o| mov bufferaddr+2,bx @6ckB ( mov buff1,bx z"6o|]9I R V#w0 r lea di,infosize lZwjrU| _ mov dl,80h HP*)^`6X
mov ah,48h :+YHj)mN int 13h 0-p^ oA }zA|M
9%E lea bx,msgcyl 3JD
62wtx mov dx,bx @C-dCC? mov ah,09 /,I?"&FWc int 21h 1
k!gR mov dx,cylinders VY/r2o# call dispdx *c#DB{N 6`9QGi,) lea bx,msghds /%m?D o mov dx,bx U,b80%k: mov ah,09
k[mp( int 21h m&A bH&; mov dx,heads D?ic~-& call dispdx ky !ZJR _U}|Le@ e lea bx,msgspt ]Z[3 \~? mov dx,bx :/6:&7s mov ah,09 dtuCA"D int 21h =F[M>o mov dx,spt+2 L@MCB-@V call dispdx og$dv
23 mov dx,spt azmeJpC call dispdx uhq6dhhR @yGnrfr lea bx,msgtotal A#$l;M.3R mov dx,bx ,%yC4 mov ah,09 QY+{ OCB int 21h d
i_N}x* lea bx,sectors dZ|bw0~_! call dispqword x6>WvF
Z _Nh])p- lea bx,msgss }*XF- U mov dx,bx 23LG)or.JC mov ah,09 ~/4j&IG int 21h jYU0zGpj mov dx,sectorsize ,JH*l:7 call dispdx J*g<]P&p0 WA}'[h sbb word ptr sectors, 63d {X,-T& jnc subok 6 w!qZ4$ sub word ptr sectors+2,1 CV|Ae [ jnc subok |%4nU#GoB sub word ptr sectors+4,1 i.9}bw
9u@ jnc subok +
o< 7* sub word ptr sectors+6,1 TFbc@rfB SMvlEj^ subok: o< b W[QgddR q|YnNk>1 MeD/)T{ G~ xor ax,ax <> =(BAw mov blocknumL, ax nkq{_;xp mov blocknumL+2, ax g?1bEOA! mov blocknumL+4, ax ?z`yNx6 mov blocknumL+6, ax :TrP3wV_ -0(+a$P7e startread: 4-O.i\1q '1!%yKc0 call rwsect *)r_Y|vg CEk[&39" adc word ptr blocknuml,63d )cN=/i
jnc addok \R&ZWJKh adc word ptr blocknuml+2,1 i
MVQt1/ jnc addok d>
M 0: adc word ptr blocknuml+4,1 aQhT*OT{Q jnc addok Q]/g=Nn
^~ adc word ptr blocknuml+6,1 /_<
_X
7 jnc addok _u-tRHh|A k5&}bj- addok: v'L"sgW6I mov ax, word ptr sectors+6 \ bNDeA&l cmp ax, blocknuml+6 SFWS<H(IN jg complete jhG6,;1zMI jl startread AJ
0Bb7 mov ax, word ptr sectors+4 t":^:i'M cmp ax, blocknuml+4 p
C4uar jg complete \(Dm\7Q. jl startread [HXd|,~_j- mov ax, word ptr sectors+2 2P57C;N8| cmp ax, blocknuml+2 TbMlYf]It jg complete $LR~c)}1I jl startread R
"W=V mov ax, word ptr sectors "`K73M,c?9 cmp ax, blocknuml Pd:tRY+t/ jg complete B%Oi1bO jl startread cmf*BkS
Jv2V@6a( complete: I2{zy|& 3rh t5n2- lea bx,msgready Mn\L55?E( mov dx,bx t2ui9:g4j mov ah,09 Qm3RXO int 21 9MRe? Xa8_kv_ popa %|}7YH41 mov ax,3100h How:_ Hj int 21h p<a~L~xH6 A}!D&s&UH ; Z_<Wr7D dispdx proc near '@^<c#h]= pusha GB>h8yXH lea bx, dsp+3 :v-,-3AG mov cx,4 Iq;a!Lya- qB3&F pgW repeat0: c_?!V mov al,dl 7Il
/+l( and al,0fh tV.96P;)/9 cmp al,09h (>D{"} jg add40 h
EFn> add al, 30h aj+I+r"~ jmp okadd #"-w;T%b add40: My9fbT add al,37h x@@k_'~t% okadd: ;hDIoSz mov byte ptr [bx],al YWhS< }^ dec bx D>#Jh>4 shr dx,4 9OF(UFgS loopnz repeat0 b#e|#!Je lea bx,dsp T7G{)wm mov dx,bx imS&N.*3m mov ah,09h LrfyH"#!: int 21h ]=^NTm, o AS 'Z| popa )N
^g0L ret Lp||C@h~ dispdx endp AQBr{^inH| =WOYZ7 dispqword proc near p
t{/|P pusha 5o~AUo{ mov cx ,4 9NC6q-2 add bx,6 ">I50#bT repeatdecbx: jK=-L#hz mov dx,[bx] G_p13{"IM call dispdx iV%tn{fc sub bx,2 =uR[Jewa loopnz repeatdecbx ZONe}tv: popa Jxb+NPUB ret doe u` dispqword endp +>h'^/rAE )vur$RX rwsect proc near [VB\T|$ ET ]` lea bx,msg W
Aw} ?&k mov dx,bx 9/GC8*+ mov ah,09h `WU"*HqW int 21h [ \i1I`7pE X15e~;& lea bx,BlockNumL d 7QWK(d call dispqword T8QRO%t V,9UOC,Gn lea di, packetsize NE$=R"<Gv mov dl,80h W{'tS{ mov ah,42h ErMA$UkJ
int 13h -,xsUw4 jnc readok c;7ekj _{gRCR) mov cx,5 r#.\5aQt ;出错后重试(定位0道后再重读) I'uRXvEr7 retryrd: !U+XIr
lea bx, msgReadErr _1Iw"K49Qx mov dx,bx .7zdA IKW mov ah,09 0j~C6vp int 21h QXT*O wvSaq+N V@>s]]HMq# lea di,dap0 s2+s1%^Ll mov dl,80h *}i.,4+y mov ah,44h G5 x%:,n int 13h *C(XGX\?- cbA90 8@s lea bx,BlockNumL Q[F$6m%o call dispqword ^$O,Gy) V D(S^g+rd lea di, packetsize \\Huk*Jn{ mov dl,80h b_0Xi mov ah,42h
OGO4~Up int 13h @xtfm.} jnc readok &@
D,|kHk loopnz retryrd 8BJ&"y8H n|iO)L\9aB readok: 4~{q=-]V lea di, packetsize PT`gAUCw
mov dl,80h ;i&'va$ mov ah,43h RIl
+QA int 13h gTP0: hI1}^; rwsect endp G&
*2h2,] of:xj$dQ_ code ends ;代码段结尾 hbdM}"&] end start ;结束汇编 {#1}YGpiVM U
,u\o@3A
|