微型计算机原理实验.docx
《微型计算机原理实验.docx》由会员分享,可在线阅读,更多相关《微型计算机原理实验.docx(19页珍藏版)》请在冰豆网上搜索。
微型计算机原理实验
实验一:
输出字符‘A’的源程序如下:
PROGSEGMENT
ASSUMECS:
PROG
START:
MOVDL,'A'
MOVAH,2
INT21H
MOVAH,4CH
INT21H
PROGENDS
ENDSTART
实验二:
1.把BX中的二进制数转换成十进制数,在屏幕上显示出来,只考虑无符号数。
程序如下:
CODESEGMENT
ASSUME
CS:
CODE
START:
MOV
BX,0FFFH
MOV
CX,10000
CALL
DEC_DIV
MOV
CX,1000
CALL
DEC_DIV
MOV
CX,100
CALL
DEC_DIV
MOV
CX,10
CALL
DEC_DIV
MOV
CX,1
CALL
DEC_DIV
MOV
AH,4CH
INT
21H
DEC_DIVPROC
NEAR
MOV
AX,BX
MOV
DX,0
DIV
CX
MOV
BX,DX
MOV
DL,AL
ADD
DL,30H
MOV
AH,2
INT
21H
RET
DEC_DIVENDP
CODEENDS
END
START
2.把BX中的带符号数转换成十进制数,在屏幕上显示出来。
程序如下:
CODESEGMENTASSUMECS:
CODE
START:
MOV
BX,8001H
MOV
AX,8000H
AND
AX,BX
JNZ
MINUS
JMP
DISP
MINUS:
MOV
DL,'-'
MOV
AH,2
INT
21H
NEG
BX
JMP
DISP
DISP:
MOV
CX,10000
CALL
DEC_DIV
MOV
CX,1000
CALL
DEC_DIV
MOV
CX,100
CALL
DEC_DIV
MOV
CX,10
CALL
DEC_DIV
MOV
CX,1
CALL
DEC_DIV
MOV
AH,4CH
INT
21H
DEC_DIVPROC
NEAR
MOV
AX,BX
MOV
DX,0
DIV
CX
MOV
BX,DX
MOV
DL,AL
ADD
DL,30H
MOV
AH,2
INT
21H
RET
DEC_DIVENDP
CODEENDS
END
START
3.求一个数据块(由10个单字节的无符号数组成)中的最大元素,并将结果在屏幕上显示出来,程序如下:
DATASEGMENT
BLOCKDB
1,0,5,7,10,30,100,127,90,80
RESULTDB
?
DATAENDS
CODESEGMENT
ASSUME
CS:
CODE,DS:
DATA
BEGINPROC
FAR
MOV
AX,DATA
MOV
DS,AX
MOV
CX,9
LEA
SI,BLOCK
MOV
AL,[SI]
X1:
INC
SI
CMP
AL,[SI]
JAE
X2
MOV
AL,[SI]
X2:
LOOP
X1
MOV
RESULT,AL
MOV
AH,0
MOV
BX,AX
CALL
XIANSHI
MOV
AH,4CH
INT
21H
BEGINENDP
XIANSHIPROC
NEAR
MOV
AL,80H
AND
AL,BL
JNZ
MINUS
JMP
DISP
MINUS:
MOV
DL,'-'
MOV
AH,2
INT
21H
NEG
BL
JMP
DISP
DISP:
MOV
CX,100
CALL
DEC_DIV
MOV
CX,10
CALL
DEC_DIV
MOV
CX,1
CALL
DEC_DIV
MOV
AH,4CH
INT
21H
XIANSHIENDP
DEC_DIVPROC
NEAR
MOV
AX,BX
MOV
DL,0
DIV
MOV
MOV
MOV
ADD
MOV
INT
CL
BL,AH
BH,0
DL,AL
DL,30H
AH,2
21H
RET
DEC_DIVENDP
CODEENDS
ENDBEGIN
4.求一个数据块(由20个单字节的带符号数组成)中的正数和(≤字)和
负数和(≤字),并在屏幕上用十进制的形式显示出两个和。
程序如下:
DATASEGMENT
BLOCKDW-100,100,200,-200,5,6,7,8,9,10
DW11,12,13,14,15,50,-50,150,-150,-200
POSITDW?
NEGATDW?
ST1DB'Thesumofallthepositivenumbers:
$'
ST2DB'Thesumofthenegativenumbers:
$'
MOVAX,DATA
MOVDS,AX
MOVBX,OFFSETBLOCK
MOVSI,0
MOVDI,0
MOVCX,20
X1:
MOVAX,[BX]
CMPAX,0
JGEX3
ADDDI,AX
JMPX2
X3:
ADDSI,AX
X2:
ADDBX,2
LOOPX1
MOVPOSIT,SI
MOVNEGAT,DI
MOV
MOV
MOV
BX,SI
DX,OFFSETST1
AH,9
INT
21H
CALL
XIANSHI
MOV
DL,0DH
MOV
AH,2
INT
21H
MOV
DL,0AH
MOV
AH,2
INT
21H
MOV
BX,NEGAT
NEG
BX
AND
BX,7FFFH
MOV
DX,OFFSETST2
MOV
AH,9
INT
21H
MOV
DL,'-'
MOV
AH,2
INT
21H
CALL
XIANSHI
MOV
AH,4CH
INT
21H
STARTENDP
XIANSHIPROC
NEAR
MOV
CX,100
CALL
DEC_DIV
MOV
CX,10
CALL
DEC_DIV
MOV
CX,1
CALL
DEC_DIV
RET
XIANSHIENDP
DEC_DIVPROC
NEAR
MOV
AX,BX
MOV
DX,0
DIV
CX
MOV
BX,DX
MOV
DL,AL
ADD
DL,30H
MOV
AH,2
INT
21H
RET
DEC_DIVENDP
CODEENDS
ENDSTART
5.将寄存器BX中的二进制数转换成十六进制数并在屏幕上显示出来。
程序如下:
CODESEGMENT
ASSUME
CS:
CODE
BINHEXPROC
FAR
MOV
CH,4
MOV
BX,1000
ROTATE:
MOV
CL,4
ROL
BX,CL
MOV
DL,BL
AND
DL,0FH
ADD
DL,30H
CMP
DL,3AH
JL
OUTPUT
ADD
DL,7
OUTPUT:
MOV
AH,2
INT
21H
DEC
CH
JNE
ROTATE
MOV
DL,'H'
MOV
AH,2
INT
21H
MOV
AH,4CH
INT
21H
BINHEXENDP
CODEENDS
END
BINHEX
实验三:
1.从键盘上输入一个十进制数(0~65535),转换成二进制数并放入寄存器BX中,其程序框图如下:
程序如下:
CODESEGMENT
ASSUMECS:
CODE
STARTPROC
CALLDECBIN
CALLXIANSHI
MOVAH,4CH
INT21H
STARTENDP
DECBINPROC
NEAR
MOV
CX,10
MOV
BX,0
LOP1:
MOV
AH,1
INT
21H
CMP
AL,30H
JL
EXIT
CMP
AL,39H
JG
EXIT
SUB
AL,30H
MOV
AH,00H
XCHG
AX,BX
MUL
CX
ADD
BX,AX
JMP
LOP1
EXIT:
RET
DECBINENDP
XIANSHIPROCNEAR
LP1:
MOVCX,10000
CALLDEC_DIV
MOVCX,1000
CALLDEC_DIV
MOVCX,100
CALLDEC_DIV
MOVCX,10
CALLDEC_DIV
MOVCX,1
CALLDEC_DIV
RET
XIANSHIENDP
DEC_DIVPROCNEAR
MOVAX,BX
MOVDX,0
DIVCX
MOVBX,DX
MOVDL,AL
ADDDL,30H
MOVAH,2
INT21H
RET
DEC_DIVENDP
CODEENDS
ENDSTART
2.从键盘上输入0~65535范围的一个十进制数,在屏幕上显示出相应的十六进制数。
程序如下:
CODESEGMENT
ASSUMECS:
CODE
STARTPROC
CALLDECBIN
MOVCH,4
CALLROTATE
MOVAH,4CH
INT21H
STARTENDP
DECBINPROC
NEAR
MOV
CX,10
MOV
BX,0
LOP1:
MOV
AH,1
INT
21H
CMP
AL,30H
JL
EXIT
CMP
AL,39H
JG
EXIT
SUB
AL,30H
MOV
AH,00H
XCHG
AX,BX
MUL
CX
ADD
BX,AX
JMP
LOP1
EXIT:
RET
DECBINENDP
ROTATEPROC
LOP2:
MOV
CL,4
ROL
BX,CL
MOV
DL,BL
AND
DL,0FH
ADD
DL,30H
CMP
DL,3AH
JL
OUTPUT
ADD
DL,7
OUTPUT:
MOV
AH,2
INT
21H
DEC
CH
JNE
LOP2
MOV
DL,'H'
MOV
AH,2
INT
21H
MOV
AH,4CH
INT
21H
ROTATEENDP
CODEENDS
END
START
实验四:
1.在内存中存有一字符串,以
0为结尾,程序开始输出‘HELLO’然后等待从键盘输入
一字符,再改字符串中寻找该字符,若找到,输出‘
yes’;若找不到,输出‘no’,然后再
输入下一字符。
程序如下:
DATA
SEGMENT
STR1
DB
'HELLO',0DH,0AH,'$'
STR2
DB
20H,'YES',0DH,0AH,'$'
STR3
DB
20H,'NO',0DH,0AH,'$'
STR4
DB
'123045ABa=!
?
',00H
DATA
ENDS
CODE
SEGMENT
ASSUME
CS:
CODE,DS:
DATA
STARTPROC
FAR
MOV
AX,DATA
MOV
DS,AX
MOV
DX,OFFSETSTR1
MOV
AH,9
INT
21H
LOOP1:
MOV
AH,1
INT
21H
MOV
BX,OFFSETSTR4
GON:
MOV
AH,[BX]
CMP
AH,0
JZ
NO
INC
BX
CMP
AH,AL
JNZ
GON
MOV
DX,OFFSETSTR2
GO:
MOV
AH,9
INT
21H
JMP
LOOP1
NO:
MOV
DX,OFFSETSTR3
JMP
GO
STARTENDP
CODE
ENDS
END
START
2.实验内容1的程序是个无限循环程序,若按‘ESC’键,让程序退出循环,是系统返
回DOS。
已知‘ESC’键的键值是
1BH,按照上面要求对实验内容
1的程序进行修改,然后
重新汇编、链接和运行。
程序如下:
DATA
SEGMENT
STR1
DB
'HELLO',0DH,0AH,'$'
STR2
DB
20H,'YES',0DH,0AH,'$'
STR3
DB
20H,'NO',0DH,0AH,'$'
STR4
DB
'123045ABa=!
?
',00H
DATA
ENDS
CODE
SEGMENT
ASSUME
CS:
CODE,DS:
DATA
STARTPROC
FAR
MOV
AX,DATA
MOV
DS,AX
MOV
DX,OFFSETSTR1
MOV
AH,9
INT
21H
LOOP1:
MOV
AH,1
INT
21H
MOV
BX,OFFSETSTR4
GON:
MOV
AH,[BX]
CMP
AH,0
JZ
NO
INC
BX
CMP
JNZ
MOV
GO:
MOV
INT
JMP
NO:
MOV
JMP
STARTENDP
CODEENDS
END
AH,AL
GON
DX,OFFSETSTR2
AH,9
21H
LOOP1
DX,OFFSETSTR3
GO
START