程序调试.docx
《程序调试.docx》由会员分享,可在线阅读,更多相关《程序调试.docx(28页珍藏版)》请在冰豆网上搜索。
程序调试
加减法参考程序
DATASEGMENTPARAPUBLIC‘DATA’
DATAENDS
STACKSEGMENTPARASTACK‘STACK’
DB512DUP(?
)
STACKENDS
CODESEGMENTPARAPUBLIC‘CODE’
ASSUMECS:
CODE,DS:
DATA,ES:
DATA,SS:
STACK
STARTPROCFAR
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVES,AX
MOVAX,0000
MOVDX,0000
MOVSI,2050H
MOVDI,2150H
MOVBP,2250H
MOVWORDPTR[SI],0205H
MOVWORDPTR[DI],0408H
MOVWORDPTR[BP],0109H
MOVAL,[SI];送被加数低8位AL=
ADDAL,[DI];低8位相加AL=,AH=,CF=
AAA;加法ASCII调整AL=,AH=,CF=
MOVDL,AL;DL=
MOVAL,[SI+1];AL=
ADCAL,[DI+1];带进位加AL=,CF=
AAA;加法ASCII调整AL=,AH=,CF=
XCHGAL,DL;AL与DL交换AL=,DL=
SUBAL,[BP];和的低8位减减数的低8位AL=
AAS;减法ASCII调整AL=,AH=,CF=
XCHGAL,DL;AL与DL交换,存低8位结果AL=,DL=
SBBAL,[BP+1];高8位带进位减AL=
AAS;减法ASCII调整AL=,AH=,CF=
MOVDH,AL;DH=
RET
STARTENDP
CODEENDS
ENDSTART
乘法参考程序
DATASEGMENTPARAPUBLIC‘DATA’
DATAENDS
STACKSEGMENTPARASTACK‘STACK’
DB512DUP(?
)
STACKENDS
CODESEGMENTPARAPUBLIC‘CODE’
ASSUMECS:
CODE,DS:
DATA,ES:
DATA,SS:
STACK
STARTPROCFAR
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVES,AX
MOVAX,0
MOVBX,0
MOVDI,223AH
MOVSI,2230H
MOVAL,04H
MOVBL,06H
…;相乘,AL=,CF=
…;调整,AH=,AL=
MOVWORDPTR[DI],AX
MOVAL,03H
…;被乘数高8位乘以乘数低8位
…;调整
…;部分积相加
…;调整
MOVWORDPTR[DI+1],AX
MOVAL,04H
MOVBL,05H
…;相乘
…;调整
MOVWORDPTR[SI],AX
MOVAL,03H
MULBL
…;调整
…;部分积相加
…;调整
MOVWORDPTR[SI+1],AX
MOVAL,[DI];
MOVBP,2240H
MOV[BP],AL
MOVAL,[DI+1]
…;部分积相加
…;调整
MOV[BP+1],AL
MOVAL,[DI+2];
…;部分积相加
…;调整
MOV[BP+2],AL
MOVAL,0
…;部分积相加
…;调整
MOV[BP+3],AL
RET
STARTENDP
CODEENDS
ENDSTART
16进制到ACII码参考程序
nameHEXASC
datasegmentparapublic'data'
hexdw0A5E9h
ascdb20dup(0)
dataends
stacksegmentparastack'stack'
db512dup(?
)
stackends
codesegmentparapublic'code'
assumecs:
code,ds:
data,es:
data,ss:
stack
startprocfar
pushds
movax,0
pushax
movax,data
movds,ax
moves,ax
movcx,0004h
movax,0EBF9H;AX=,取十六进制数0ebf9h
leabx,asc
aa:
pushcx
movcl,4;给循环计数器赋转换代码长度
rolax,cl;AX=,十六进制数循环左移
pushax
andax,000fh;AX=;AX=AX=;AX=
cmpal,0AH;判别是否为“0~9”
JCascii;是“0~9”转ascii
addal,07h
ascii:
addal,30h;al=;al=al=;al=
loopaa
ret
startendp
codeends
endstart
datasegmentparapublic'data'
hexdw0A5E9h
ascdb20dup(0)
dataends
stacksegmentparastack'stack'
db512dup(?
)
stackends
codesegmentparapublic'code'
assumecs:
code,ds:
data,es:
data,ss:
stack
startprocfar
pushds
movax,0
pushax
movax,data
movds,ax
moves,ax
movcx,0004h
movax,0EBF9H;AX=,取十六进制数0ebf9h
leabx,asc
aa:
pushcx
movcl,4;给循环计数器赋转换代码长度
rolax,cl;AX=,十六进制数循环左移
pushax
andax,000fh;AX=;AX=AX=;AX=
cmpal,0AH;判别是否为“0~9”
JCascii;是“0~9”转ascii
addal,07h
ascii:
addal,30h;al=;al=al=;al=
popax
popcx
loopaa
ret
startendp
codeends
endstart
ACII码到BCD码参考程序
NAMEASCBCD
DATASEGMENTPARAPUBLIC'DATA'
ORG0150H
DATA1DW3538H,4237H,3946H,3639H,3642H
ORG0160H
DB10DUP(?
)
DATAENDS
STACKSEGMENTPARASTACK'STACK'
DB512DUP(?
)
STACKENDS
CODESEGMENTPARAPUBLIC'CODE'
ASSUMECS:
CODE,DS:
DATA,ES:
DATA,SS:
STACK
STARTPROCFAR
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVES,AX
MOVCX,05H
…;DI=,[DI]=ASCII首址送DI
…;SI=,BCD首址送SI
BB:
MOVBL,0FFH
MOVAL,[DI];AL=
…;检查是否为大于9的ASCII码
…;是转DONE
…;AL=,[DI]=不是,取ASCII码低4位
…;小于0的十进制数,转DONE
MOVBL,AL
DONE:
MOVAL,BL;AL=,[DI]=
MOV[SI],AL;[SI]=
…;指针加1
…;指针加1
…;(CX)不为0,转BB
RET[160H]=
STARTENDP
CODEENDS
ENDSTART
BCD码→二进制参考程序
NAMEBCD2
DATASEGMENT
ORG0180H
DAT1DW0802H,0103H,0009H,0706H,0407H
ORG0190H
DAT2DB10DUP(?
)
DATAENDS
STACKSEGMENTPARASTACK'STACK'
DB512DUP(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,ES:
DATA,SS:
STACK
STARTPROCFAR
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVES,AX
…;循环计数器赋转换代码长度
…;BCD码首址送DI
…;二进制首址送SI
XL:
…;BCD码十位数值赋AL
MOVBL,0AH
MULBL;乘10
INCDI
MOVAH,00H
…;BCD码十位和个位相加,转换结束
…;转换结果存二进制起始地址
INCDI
INCDI
INCSI;(CX)不为0转AA
LOOPXL
RET
STARTENDP
CODEENDS
ENDSTART
查表处理参考程序
DATASEGMENT
LISTDW12,11H,22H,33H,44H,55H,66H,77H,88H,99H,111H,222H,333H
DATAENDS
CODESEGMENT
DEL_ULPROCFAR
ASSUMECS:
CODE,DS:
DATA,ES:
DATA
MAIN:
PUSHDS
SUBAX,AX
PUSHAX
MOVAX,DATA
MOVDS,AXMOVES,AXMOVAX,55H;AX=
CLD
LEADI,LIST;DI=,[DI]=取得数据区首地址PUSHDI
MOVCX,ES:
[DI]
ADDDI,2
REPNZSCASW;AX=,DI=,[DI]=字符串比较
JZDELETE;字符相同转移
JMPSHORTEXIT
DELETE:
JCXZDEC_CNT;CX寄存器内容为0则到数据区尾转结束
NEXT_EL:
MOVBX,ES:
[DI];BX=,[DI-2]
MOVES:
[DI-2],BX;(DI-2)=,(DI)=
ADDDI,2
LOOPNEXT_EL
DEC_CNT:
POPDI
DECWORDPTRES:
[DI];(0H)=……….
EXIT:
RETDEL_ULENDP
CODEENDSENDMAIN
分支与循环参考程序
DATASEGMENT
ORG200H
ARRAYDW56H,12H,-6790H,0,78H,0H,-1H,0H,3000H,90H
DATAENDS
CODESEGMENT
MAINPROCFAR
ASSUMECS:
CODE,DS:
DATA
START:
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVCX,10;循环计数器赋转换代码长度
MOVBX,0
MOVDI,BX
MOVSI,BX
MOVBX,200H;BX=字数组首址送BX
AGAIN:
MOVAX,[BX]
CMPAX,0000H;与0比较
JNGLEQ;小于或等于0转
INCDI;AX=,DI=
JMPSHORTNEXT
LEQ:
JNGENEXT;小于0转
INCSI;AX=,SI=
NEXT:
ADDBX,2
LOOPAGAIN
MOVAX,10
SUBAX,DI;字数组长度减正数
SUBAX,SI;AX=字数组长度减正数再减零
RET
MAINENDP
CODEENDS
ENDSTART
排序参考程序
DATASEGMENT
DATDW10,1234H,2345H,3456H,9999H
DW8700H,7000H,0,6500H,5111H,4FBDH
DATAENDS
CODESEGMENT
MAINPROCFAR
ASSUMECS:
CODE,DS:
DATA,ES:
DATA
START:
PUSHDS;初始化
SUBAX,AX
PUSHAX
MOVAX,DATA
MOVDS,AX
MOVES,AX
leadi,dat;字数组首地址送DI
movcx,[di];循环长度送CX
deccx;循环长度减1(10个数据,循环9次)
LOOP1:
MOVSI,CX
INCDI
INCDI
LOOP2:
movax,[di];取DAT(I)个数据
cmpax,[di+1];与DAT(I+1)个数据比较
jccon;如果DAT(I+1)大于或等于DAT(I)转移
xchgax,[di+1];AX=,(DI)=否则交换
movdi,ax;(DI)=存较小的数
CON:
ADD
DI,2
LOOPLOOP2
movcx,[di];(DI)=…….取循环长度,准备下次比较
leadi,dat;字数组首地址送DI
LOOPLOOP1;(DI)=……..
RET
MAINENDP
CODEENDS
ENDSTART
6264参考程序
.486
DATASEGMENTAT0USE16
ORG4000H
DATA1DB6DUP(?
)
DATAENDS
CODESEGMENTUSE16
ASSUMECS:
CODE,DS:
DATA,ES:
DATA
ORG2000H
BEG:
JMPSTART
START:
MOVAX,DATA
MOVDS,AX
MOVES,AX
MOVAX,0
MOVSS,AX
MOVSP,1000H
MOVAX,…;6264段地址
MOVDS,AX
XORAX,AX
MOVBX,…;偏移地址
MOVCX,…;数据长度
M1:
MOVBYTEPTR[BX],AL;(BX)=,(BX)=,(BX)=送数据
INCAL
INCBX
LOOPM1
HART
ENDP
CODEENDS
ENDBEG
8255参考程序
.486
DATASEGMENTAT0USE16
PORTAEQU…;A口
PORTBEQU…;B口
PORTCEQU…;C口
CONTROLEQU20FH;控制口
PORT1EQU340H;七段码段地址
PORT2EQU360H;七段码位地址
ORG…H
DATA1DB6DUP(?
);输入数据区
ORG…H
DATA2DB6DUP(?
);显示缓冲区
DATAENDS
CODESEGMENTUSE16
ASSUMECS:
CODE,DS:
DATA,ES:
DATA
ORG2000H
BEG:
JMPSTART
TABDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH
DB67H,77H,7CH,39H,5EH,79H,71H;段码表
STlART:
MOVAX,DATA;初始化
MOVDS,AX
MOVES,AX
MOVAX,0
MOVSS,AX
MOVSP,1000H
…;8255初始化
…
…;清显示
…
LP:
…;读数据
…
…;存数据
…
CALLCZ;调用拆字子程序
CALLDISP;调用显示子程序
JMP…;循环取数显示
CZPROC
PUSHCX
LEASI,DATA1;拆字,取数
LEADI,DATA2;显示缓冲区首址
CZ0:
MOVBL,[SI]
ANDBL,0F0H;BL=
MOVCL,4
ROLBL,CL
MOV[DI],BL;(DI)=
INCDI
MOVBL,[SI]
ANDBL,0FH;BL=
MOV[DI],BL
INCSI
INCDI
CMPSI,…H
JBECZ0
POPCX
RET
CZENDP
DISPPROC;显示子程序
PUSHCX
PUSHDX
LEABX,TAB
LEASI,DATA2
MOVAH,0C1H
DISP1:
MOVDX,PORT2
MOVAL,AH
OUTDX,AL;AL=,AL=位输出
MOVDX,PORT1
MOVAL,[SI]
XLAT
OUTDX,AL;AL=,AL=段输出
MOVCX,0200H
LOOP$
INCSI
SALAH,1
ORAH,0C0H
CMPAH,0C0H
JNZDISP1
POPDX
POPCX
RET
DISPENDP
CODEENDS
ENDBEG
8253参考程序
.486
DATASEGMENTAT0USE16
ZDXLEQU20H;中断向量(20H)
OPORTEQU3A0H;8259偶地址
JPORTEQU3A8H;8259奇地址
PORT1EQU340H;段地址
PORT2EQU360H;位地址
DS0EQU300H;8253通道0
DSCEQU30CH;8253控制口
COUNTEQU50
ORG4000H
DATA1DB6DUP(?
)
ORG4040H
DATA2DB3DUP(?
)
DATAENDS
CODESEGMENTUSE16
ASSUMECS:
CODE,DS:
DATA,ES:
DATA
ORG2000H
BEG:
CLI
JMPSTART
TABDB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,
DB7FH,67H,77H,7CH,39H,5EH,79H,71H;段码表
TIMERDB0;延时、计数初值
START:
…;初始化
INIT8253:
MOVDX,DSC
MOVAL,…;方式3,方波发生器
OUTDX,AL
MOVDX,DS0
MOVAL,0BH
OUTDX,AL
MOVAL,0E9H
OUTDX,AL
SETVECT:
MOVDI,0
MOVDX,OFFSETSERVER;中断服务子程序偏移地址
;送中断向量低位
MOVZDXL[DI],DX
MOVDX,CS;中断服务子程序段地址
;送中断向量高位
MOVZDXL[DI+2],DX,(00:
20H)
INIT8259:
MOVAL,00010011B;ICW1
MOVDX,OPORT
OUTDX,AL
MOVAL,00001000B;ICW2
MOVDX,JPORT
OUTDX,AL
MOVAL,00001101B;ICW4
MOVDX,JPORT
OUTDX,AL
MOVAL,11111110B;OCW1
MOVDX,JPORT
OUTDX,AL
MOVAL,20H;EOI(20H)
MOVDX,OPORT
OUTDX,AL
AGAIN:
STI;开中断
CALLCZ;调拆字
CALLDISP;调显示
JMPAGAIN
CZPROC
…
RET
CZENDP
DISPPROC
…
RET
DISPENDP
;--------------------------------------
SERVERPROC;8253中断入口
CLI
PUSHAX
P