汇编第六章答案.docx
- 文档编号:6331603
- 上传时间:2023-01-05
- 格式:DOCX
- 页数:23
- 大小:96.85KB
汇编第六章答案.docx
《汇编第六章答案.docx》由会员分享,可在线阅读,更多相关《汇编第六章答案.docx(23页珍藏版)》请在冰豆网上搜索。
汇编第六章答案
第六章答案
=======================================
1.下面的程序段有错吗?
若有,请指出错误.
CRAYPROC
PUSHAX
ADDAX,BX
RET
ENDPCRAY
[解]:
当然有错误,ENDPCRAY写反了,应该将其改成CRAYENDP.
2.已知堆栈寄存器SS的内容是0F0A0H,堆栈指示器SP的内容是00B0H,先执行两条把8057H和0F79BH分别入栈的PUSH指令.然后再执行一POP指令.试画出示意图说明堆栈及SP内容的变化过程.
3.分析下面"6,3的程序",画出堆栈最满时各单元的地址及内容.
; 6.3题的程序
;===========================================
S_SEGSEGMENTAT1000H;DEFINESTACKSEGMENT
DW200DUP(?
)
TOSLABELWORD
S_SEGENDS
C_SEGSEGMENT;DEFINECODESEGMENT
ASSUMECS:
C_SEG,SS:
S_SEG
MOVAX,S_SEG
MOVSS,AX
MOVSP,OFFSETTOS
PUSHDS
MOVAX,0
PUSHAX
...
PUSHT_ADDR
PUSHAX
PUSHF
...
POPF
POPAX
POPT_ADDR
RET
C_SEGENDS;ENDOFCODESEGMENT
ENDC_SEG;ENDOFASSEMBLY
4.分析下面"6.4题的程序"的功能,写出堆栈最满时各单元的地址及内容.
; 6.4题的程序
;====================================
STACKSEGMENTAT500H
DW128DUP(?
)
TOSLABELWORD
STACKENDS
CODESEGMENT;DEFINECODESEGMENT
MAINPROCFAR;MAINPARTOFPROGRAM
ASSUMECS:
CODE,SS:
STACK
START:
;STARTINGEXECUTIONADDRESS
MOVAX,STACK
MOVSS,AX
MOVSP,OFFSETTOS
PUSHDS
SUBAX,AX
PUSHAX
;MAINPARTOFPROGRAMGOESHERE
MOVAX,4321H
CALLHTOA
RET ;RETURNTODOS
MAINENDP;ENDOFMAINPARTOFPROGRAM
HTOAPROCNEAR;DEFINESUBPROCEDUREHTOA
CMPAX,15
JLEB1
PUSHAX
PUSHBP
MOVBP,SP
MOVBX,[BP+2]
ANDBX,000FH
MOV[BP+2],BX
POPBP
MOVCL,4
SHRAX,CL
CALLHTOA
POPAX
B1:
ADDAL,30H
CMPAL,3AH
JLPRINTIT
ADDAL,07H
PRINTIT:
MOVDL,AL
MOVAH,2
INT21H
RET
HTOAENDP;ENDOFSUBPROCEDURE
CODEENDS;ENDOFCODESEGMENT
ENDSTART;ENDOFASSEMBLY
5.下面是6.5题的程序清单,请在清单中填入此程序执行过程中的堆栈变化.
0000 STACKSGSEGMENT
000020[.DW32DUP(?
)
?
?
?
?
0040 ]
STACKSGENDS
0000 CODESGSEGMENTPARA'CODE'
0000 BEGINPROCFAR
ASSUMECS:
CODESG,SS:
STACKSG
00001E PUSHDS
00012BC0SUBAX,AX
000350 PUSHAX
0004E80008RCALLP10
0007CB RET
0008 BEGINENDP
0008 B10PROC
0008E8000CRCALLC10
000BC3 RET
000C B10ENDP
000C C10PROC
000CC3 RET
000D C10ENDP
000D CODESGENDS
ENDBEGIN
6.写一段子程序SKIPLINES,完成输出空行的功能.空行的行数在AX寄存器中.
[解]:
SKIPLINESPROCNEAR
PUSHCX
PUSHDX
MOVCX,AX
NEXT:
MOVAH,2
MOVDL,0AH
INT21H
MOVAH,2
MOVDL,0DH
INT21H
LOOPNEXT
POPDX
POPCX
RET
SKIPLINESENDP
7.设有10个学生的成绩分别是76,69,81,90,73,88,99,63,100和80分.试编制一个子程序统计60-69,70-79,80-89,90-99和100分的人数并分别存放到S6,S7,S8,S9和S10单元中.
DSEGSEGMENT
NUMDW76,69,84,90,73,88,99,63,100,80
NDW10
S6DW0
S7DW0
S8DW0
S9DW0
S10DW0
DSEGENDS
CODESEGMENT
MAINPROCFAR
ASSUMECS:
CODE,DS:
DSEG
START:
PUSHDS
SUBAX,AX
PUSHAX
MOVAX,DSEG
MOVDS,AX
CALLSUB1
RET
MAINENDP
SUB1PROCNEAR
PUSHAX
PUSHBX
PUSHCX
PUSHSI
MOVSI,0
MOVCX,N
NEXT:
MOVAX,NUM[SI]
MOVBX,10
DIVBL
MOVBL,AL
CBW
SUBBX,6
SALBX,1
INCS6[BX]
ADDSI,2
LOOPNEXT
POPSI
POPCX
POPBX
POPAX
RET
SUB1ENDP
CODEENDS
ENDSTART
(解法二)
datasgsegment
grade db76,69,84,90,73,88,99,63,100,80
s6 db0
s7 db0
s8 db0
s9 db0
s10 db0
mess6db'60~69:
$'
mess7db'70~79:
$'
mess8db'80~89:
$'
mess9db'90~99:
$'
mess10db'100:
$'
datasgends
codesgsegment
main procfar
assumecs:
codesg,ds:
datasg
start:
pushds
subax,ax
pushax
movax,datasg
movds,ax
callsub1
leadx,mess6
calldispstr
movdl,s6
calldispscore
callcrlf
leadx,mess7
calldispstr
movdl,s7
calldispscore
callcrlf
leadx,mess8
calldispstr
movdl,s8
calldispscore
callcrlf
leadx,mess9
calldispstr
movdl,s9
calldispscore
callcrlf
leadx,mess10
calldispstr
movdl,s10
calldispscore
callcrlf
ret
main endp
sub1 procnear
movcx,10
movsi,0
loop1:
moval,grade[si]
cmpal,60
jl next5
cmpal,70
jgenext1
incs6
jmpshortnext5
next1:
cmpal,80
jgenext2
incs7
jmpshortnext5
next2:
cmpal,90
jgenext3
incs8
jmpshortnext5
next3:
cmpal,100
jgnext5
jenext4
incs9
jmpshortnext5
next4:
incs10
next5:
incsi
looploop1
ret
sub1 endp
dispstrprocnear
movah,9
int21h
dispstrendp
dispscoreprocnear
adddl,30h
movah,2
int21h
dispscoreendp
crlfprocnear
movdl,0dh
movah,2
int21h
movdl,0ah
movah,2
int21h
ret
crlfendp
codesgends
endstart
8.编写一个有主程序和子程序结构的程序模块.子程序的参数是一个N字节数组的首地址TABLE,数N及字符CHAR.要求在N字节数组中查找字符CHAR,并记录该字符的出现次数.;主程序则要求从键盘接收一串字符以建立字节数组TABLE,并逐个显示从键盘输入的每个字符CHAR以及它在TABLE数组中出现的次数.(为简化起见,假设出现次数<=15,可以用十六进制形式显示出来)
[解]:
DATASEGMENT
MAXLENDB40
NDB?
TABLEDB40DUP(?
)
CHARDB'A';查找字符'A'
EVEN
_ADDRDW3DUP(?
)
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
MAINPROCFAR
START:
PUSHDS
MOVAX,0
PUSHAX
MOVAX,DATA
MOVDS,AX
LEADX,MAXLEN
MOVAH,0AH
INT21H ;从键盘接收字符串
MOV_ADDR,OFFSETTABLE
MOV_ADDR+2,OFFSETN
MOV_ADDR+4,OFFSETCHAR
MOVBX,OFFSET_ADDR;通过地址表传送变量地址
CALLCOUNT ;计算CHAR的出现次数
CALLDISPLAY;显示
RET
MAINENDP
COUNTPROCNEAR;COUNT子程序
PUSHSI
PUSHDI
PUSHAX
PUSHCX
MOVDI,[BX]
MOVSI,[BX+2]
MOVCL,BYTEPTR[SI]
MOVCH,0
MOVSI,[BX+4]
MOVAL,BYTEPTR[SI]
MOVBX,0
AGAIN:
CMPAL,BYTEPTR[DI]
JNEL1
INCBX
L1:
INCDI
LOOPAGAIN
POPCX
POPAX
POPDI
POPSI
RET
COUNTENDP
DISPLAYPROCNEAR;DISPLAY子程序
CALLCRLF ;显示回车和换行
MOVDL,CHAR
MOVAH,2
INT21H
MOVDL,20H
MOVAH,2
INT21H
MOVAL,BL
ANDAL,0FH
ADDAL,30H
CMPAL,3AH
JLPRINT
ADDAL,7
PRINT:
MOVDL,AL
INT21H
CALLCRLF
RET
DISPLAYENDP
CRLFPROCNEAR;CRLF子程序
MOVDL,0DH
MOVAH,2
INT21H
MOVDL,0AH
MOVAH,2
INT21H
RET
CRLFENDP
CODEENDS
ENDSTART
9.编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来.
主程序TELIST:
(1)显示提示符INPUTNAME:
;
(2)调用子程序INPUT_NAME输入姓名:
(3)显示提示符INPUTATELEPHONENUMBER:
;
(4)调用子程序INPHONE输入电话号码;
(5)调用子程序PRINTLINE显示姓名及电话号码;
子程序INPUT_NAME:
(1)调用键盘输入子程序GETCHAR,把输入的姓名存放在INBUF缓冲区中;
(2)把INBUF中的姓名移入输出行OUTNAME;
子程序INPHONE:
(1)调用键盘输入子程序GETCHAR,把输入的8位电话号码存放在INBUF缓冲区中;
(2)把INBUF中的号码移入输出行OUTPHONE.
子程序PRINTLINE:
显示姓名及电话号码,格式为:
NAME TEL
**** ********
==========================================
;编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来
(解法一)
datasegment
No_of_namedb20
No_of_phonedb8
inbufdb20dup(?
)
outnamedb20dup(?
),'$'
outphonedb8dup(?
),'$'
message1db'pleaseinputname:
','$'
message2db'pleaseinputatelephonenumber:
','$'
message3db'NAME',16dup(20h),'TEL.',13,10,'$'
errormessage1db'youshouldinput8numbers!
',13,10,'$'
errormessage2db'youinputawrongnumber!
',13,10,'$'
flagdb?
dataends
progsegment
mainprocfar
assumecs:
prog,ds:
data
start:
pushds
subax,ax
pushax
movax,data
movds,ax
movflag,0
leadx,message1
movah,09
int21h
callinput_name
callcrlf
leadx,message2
movah,09
int21h
callinphone
callcrlf
cmpflag,1
je exit
callprintline
exit:
ret
mainendp
input_nameprocnear
pushax
pushdx
pushcx
movcx,0
movcl,No_of_name
callgetchar
movax,0
moval,No_of_name
subax,cx
movcx,ax
movsi,0
next1:
moval,inbuf[si]
movoutname[si],al
incsi
loopnext1
popcx
popdx
popax
ret
input_nameendp
inphoneprocnear
pushax
pushdx
movcx,0
movcl,No_of_phone
callgetchar
cmpcx,0
jnzerror1
movcl,No_of_phone
movsi,0
next2:
moval,inbuf[si]
cmpal,30h
jl error2
cmpal,39h
ja error2
movoutphone[si],al
incsi
loopnext2
jmpexit2
error1:
callcrlf
leadx,errormessage1
movah,09
int21h
movflag,1
jmpexit2
error2:
callcrlf
leadx,errormessage2
movah,09
int21h
movflag,1
jmpexit2
exit2:
popdx
popax
ret
inphoneendp
getcharprocnear
pushax
pushdx
movdi,0
rotate:
movah,01
int21h
cmpal,0dh
je exit1
movinbuf[di],al
incdi
looprotate
exit1:
popdx
popax
ret
getcharendp
crlfprocnear
pushax
pushdx
movdl,0dh
movah,2
int21h
movdl,0ah
movah,2
int21h
popdx
popax
ret
crlfendp
printlineprocnear
pushax
pushdx
leadx,message3
movah,09
int21h
leadx,outname
movah,09
int21h
leadx,outphone
movah,09
int21h
popdx
popax
ret
printlineendp
progends
endmain
==========================================
;从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来
datareasegment
inbuf label byte ;nameparameterlist:
maxnlen db
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汇编 第六 答案