计算机原理习题4.docx
- 文档编号:9244616
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:20
- 大小:25.92KB
计算机原理习题4.docx
《计算机原理习题4.docx》由会员分享,可在线阅读,更多相关《计算机原理习题4.docx(20页珍藏版)》请在冰豆网上搜索。
计算机原理习题4
习题4:
请编写完整汇编程序:
1.内存中以BUF单元开始存放8个16位二进制数,试编程将8个数倒序后存放于BUF开始的单元,试编程;(提示:
采用堆栈实现)
DATASEGMENT
ORG0000H
BUFDW1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H
COUNTEQU($-BUF)/2
MES1DB'BUF:
',0AH,0DH,'$'
DATAENDS
STACK1SEGMENTSTACK
DW256DUP(0)
STACK1ENDS
CODESEGMENT
ASSUMECS:
CODE,SS:
STACK1,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVAX,STACK1
MOVSS,AX
MOVDX,OFFSETMES1
MOVAH,09H
INT21H
LEASI,BUF
MOVCX,COUNT
LOP1:
MOVAX,[SI]
PUSHAX
INCSI
INCSI
LOOPLOP1
LEASI,BUF
MOVCX,COUNT
LOP2:
POPAX
MOV[SI],AX
INCSI
INCSI
LOOPLOP2
MOVCX,16
LEABX,BUF
LOP3:
MOVDL,[BX]
INCBX
MOVDH,DL
PUSHCX
MOVCL,4
SHRDL,CL
POPCX
ANDDL,0FH
CALLDISPLAY
MOVDL,DH
ANDDL,0FH
CALLDISPLAY
LOOPLOP3
MOVAX,4C00H
INT21H
DISPLAYPROC
CMPDL,09H
JBENEXT
ADDDL,07H
NEXT:
ADDDL,30H
MOVAH,02H
INT21H
RET
DISPLAYENDP
CODEENDS
ENDSTART
2.将8个16位无符号数相加,结果保存在32位无符号数SUM中;
DATASEGMENT
BUFDW1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H
COUNTEQU($-BUF)/2
SUMDD0
MES1DB'SUM:
',0AH,0DH,'$'
DATAENDS
STACK1SEGMENTSTACK
DW100DUP(0)
STACK1ENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,SS:
STACK1
START:
MOVAX,DATA
MOVDS,AX
MOVDX,OFFSETMES1
MOVAH,09H
INT21H
LEABX,BUF
MOVCX,COUNT
MOVDX,0000H
LOP:
MOVAX,[BX]
ADDWORDPTRSUM,AX
ADCWORDPTRSUM+2,DX
INCBX
INCBX
LOOPLOP
MOVCX,4
LEABX,SUM
LOP3:
MOVDL,[BX]
INCBX
MOVDH,DL
PUSHCX
MOVCL,4
SHRDL,CL
POPCX
ANDDL,0FH
CALLDISPLAY
MOVDL,DH
ANDDL,0FH
CALLDISPLAY
LOOPLOP3
MOVAX,4C00H
INT21H
DISPLAYPROC
CMPDL,09H
JBENEXT
ADDDL,07H
NEXT:
ADDDL,30H
MOVAH,02H
INT21H
RET
DISPLAYENDP
CODEENDS
ENDSTART
3.以十进制形式在计算机屏幕上显示内存中的一个8位有符号数,例如:
若内存单元中存放的数据为7FH,则在屏幕上显示+127,若内存单元存放的数据为0FFH,则应在屏幕上显示-1;
DATASEGMENT
VARDB0FFH
STR1DB'THERESULTIS:
$'
DATAENDS
SS_SEGSEGMENTSTACK
DW100DUP(0)
SS_SEGENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,SS:
SS_SEG
START:
MOVAX,DATA
MOVDS,AX
LEADX,STR1
MOVAH,09H
INT21H
MOVDL,'+'
CMPVAR,0
JGENEXT
MOVDL,'-'
NEGVAR
NEXT:
MOVAH,02H
INT21H
MOVAL,VAR
MOVBL,10
MOVCL,0
LOP1:
ANDAH,0
DIVBL
PUSHAX
INCCL
CMPAL,0
JNZLOP1
LOP2:
POPAX
MOVDL,AH
ADDDL,30H
MOVAH,2
INT21H
LOOPLOP2
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
4.从键盘输入一个4位十进制数,然后以16进制形式显示在屏幕上,试编程;
例如:
输入1024在屏幕上应该显示0400H
DATASEGMENT
STR1DB'INPUTDATA:
$'
BUFDB20
DB4
DB4DUP(?
)
STR2DB0AH,0DH,'THERESULTIS:
','$'
DATAENDS
SS_SEGSEGMENTSTACK
DB100DUP(0)
SS_SEGENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,SS:
SS_SEG
START:
MOVAX,DATA
MOVDS,AX
LEADX,STR1
MOVAH,09H
INT21H
MOVAH,0AH
LEADX,BUF
INT21H
MOVCX,03H
LEASI,BUF+2
ANDBX,0H
MOVDL,0AH
LOP1:
MOVAL,[SI]
SUBAL,30H
PUSHCX
LOP2:
MULDL
LOOPLOP2
POPCX
ADDBX,AX
INCSI
LOOPLOP1
ANDCH,00H
MOVCL,[SI]
SUBCL,30H
ADDBX,CX
LEADX,STR2
MOVAH,09H
INT21H
MOVAX,BX
ANDCH,00H
MOVCL,04H
MOVDH,04H
MOVDL,00H
AAA1:
ANDAX,000FH
PUSHAX
DECDH
INCDL
SHRBX,CL
MOVAX,BX
CMPDH,0
JAAAA1
MOVCL,DL
BBB:
POPDX
CMPDL,09H
JBNEXT
ADDDL,07H
NEXT:
ADDDL,30H
MOVAH,2
INT21H
LOOPBBB
MOVDL,'H'
MOVAH,02H
INT21H
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
5.数据段中存放有一个无符号字数据VAR,将其转换成非压缩格式的BCD码,存于BUF开始的单元中(高位在前);
例如:
若VAR为0800H,则转换后(BUF)=20H(BUF+1)=48H
DATASEGMENTPARA
VARDW0800H
BUFDB2DUP(0)
DATAENDS
SS_SEGSEGMENTSTACK
DW100DUP(0)
SS_SEGENDS
CODESEGMENTPARA
ASSUMECS:
CODE,DS:
DATA,SS:
SS_SEG
START:
MOVAX,DATA
MOVDS,AX
MOVCX,16
MAIN1:
SHLVAR,1
MOVBX,4
PUSHCX
MOVCX,5
MAIN2:
MOVAL,BUF[BX]
ADCAL,AL
AAA
MOVBUF[BX],AL
DECBX
LOOPMAIN2
POPCX
LOOPMAIN1
EXIT:
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
6.内存中以str1和str2开始分别存放了两个字符串,结束符为NULL(ASCII码为0),将str2连接到str1后,形成1个字符串,并将连接后的字符串str1输出到屏幕上;
DATASEGMENT
STR1DB'GOODMORNING,',00H
STRDB50DUP(0)
STR2DB'MrWANG!
',0AH,0DH,00H
DATAENDS
SS_SEGSEGMENTSTACK
DW100DUP(0)
SS_SEGENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,SS:
SS_SEG
START:
MOVAX,DATA
MOVDS,AX
LEASI,STR1
MOVAL,[SI]
CMPAL,00H
JEJP1
JP2:
INCSI
MOVAL,[SI]
CMPAL,00H
JAJP2
JP1:
MOVCX,01H
LEABX,STR2
MOVAH,[BX]
MOV[BX],AH
CMPAH,00H
JEJP3
MOV[SI],AH
JP4:
INCSI
INCBX
INCCX
MOVAH,[BX]
MOV[SI],AH
CMPAH,00H
JAJP4
JP3:
INCSI
MOV[SI],BYTEPTR'$'
LEADX,STR1
MOVAH,09H
INT21H
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
7.统计10个有符号字节数中,大于0、小于0、等于0的个数,分别存放在NUM1、NUM2、NUM3三个变量中,并找出最大值、最小值分别存放到MAX、MIN变量中,再求10个数的和,将结果存放到16位有符号数SUM中。
DATASEGMENT
NUMDB0F0H,03H,0B4H,0AH,0AAH,00H,80H,7FH,99H,21H
COUNTEQU($-NUM)
ORG0010H
NUM1DB0
NUM2DB0
NUM3DB0
MINDB0
MAXDB0
SUMDW0
DATAENDS
SS_SEGSEGMENTSTACK
DW100DUP(0)
SS_SEGENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA,SS:
SS_SEG
START:
MOVAX,DATA
MOVDS,AX
MOVSS,AX
LEASI,NUM
MOVCX,COUNT
MOVBX,0000H
MOVDX,0000H
LOP:
MOVAL,[SI]
INCSI
CMPAL,0
JGDA
JLXIAO
JEDENG
DA:
INCBH
JMPAAA1
XIAO:
INCBL
JMPAAA1
DENG:
INCDH
AAA1:
LOOPLOP
LEASI,NUM1
MOV[SI],BH
LEASI,NUM2
MOV[SI],BL
LEASI,NUM3
MOV[SI],DH
MOVCX,COUNT-1
MAIN1:
LEABX,NUM
PUSHCX
MAIN2:
MOVAL,[BX]
INCBX
CMPAL,[BX]
JLENEXT
XCHGAL,[BX]
MOV[BX-1],AL
NEXT:
LOOPMAIN2
POPCX
LOOPMAIN1
LEASI,MIN
MOVAL,NUM
MOV[SI],AL
LEASI,MAX
MOVBL,NUM+9
MOV[SI],BL
MOVSI,OFFSETNUM
MOVCX,COUNT
MOVAX,0
LOP2:
ANDBX,0
MOVBL,[SI]
ADDAX,BX
INCSI
LOOPLOP2
LEASI,SUM
MOV[SI],AX
MOVAX,4C00H
INT21H
CODEENDS
ENDSTART
8若程序的数据段定义如下,写出各指令语句独立执行后的结果。
DSEGSEGMENT
DATA1DB10H,20H,30H
DATA2DW10DUP(?
)
StringDB‘123’
DSEGENDS
(1)MOVAL,DATA110H->AL
(2)MOVBX,offsetDATA2DATA2代表的首地址赋给BX
(3)LEASI,StringString代表的首地址赋给BX
ADDDI,SISI+DI->DI
9假设数据项定义如下:
DATA1DB‘HELLO!
GOODMORNING’
DATA2DB20DUP(?
)
用串操作指令编写程序段,使其分别完成一下功能。
(1)从左到右将DATA1中的字符串传送到DATA2中;
LEASI,DATA1
LEADI,DATA2
MOVCX,20
CLD
REPMOVSB
(2)传送完后,比较DATA1和DATA2中的内容是否相同;
LEASI,DATA1
LEADI,DATA2
MOVCX,20
CLD
REPECMPSB
(3)把DATA1中的第3个字节和第四个字节装入AX;
LEASI,DATA1
ADDSI,2
LODSW
(4)将AX的内容存入DATA2+5开始的字节单元中;
LEADI,DATA2
ADDDI,5
STOSW
10执行下列指令后,AX寄存器中的内容是多少?
TABLEDW10,20,30,40,50
ENTRYDW3
……
MOVBX,OffsetTABLE
ADDBX,ENTRY
MOVAX,[BX][AX]=1400H
存储器
11图示以下数据段在存储器中的存放形式;
10H
34H
07H
09H
42H
00H
42H
00H
48H
45H
4CH
4CH
4FH
21H
CDH
ABH
00H
00H
DATASEGMENT
DATA1 DB10H,34H,07H,09H
DATA2 DW2DUP(42H)
DATA3DB‘HELLO!
’
DATA4EQU12
DATA5DDABCDH
DATAENDS
12阅读下边的程序段,试说明它实现的功能是什么?
DATASEGMENT
DATA1DB'ABCDEFG'
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
AAAA:
MOVAX,DATA
MOVDS,AX
MOVBX,OFFSETDATA1
MOVCX,7
NEXT:
MOVAH,2
MOVAL,[BX]
XCHGAL,DL
INCBX
INT21H
LOOPNEXT
MOVAH,4CH
INT21H
CODEENDS
ENDAAAA
此程序功能为:
输出字符串‘ABCDEFG’。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 原理 习题
![提示](https://static.bdocx.com/images/bang_tan.gif)