《微機原理編程題【參照內容】》由會員分享,可在線閱讀,更多相關《微機原理編程題【參照內容】(6頁珍藏版)》請在裝配圖網上搜索。
1、
微機原理編程題
1. 分支程序設計
①.編寫一段程序,已知BUF1單元中有一帶符號字節(jié)數(shù)據(jù)X,BUF2中有一帶符號字節(jié)數(shù)據(jù)Y,根據(jù)以下函數(shù)關系編寫程序求Z的值,結果存入RESULT 單元。Z=|X-Y|;
DATA SEGMENT
BUF1 DB 05H
BUF2 DB 02H
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AL,BUF1
MOV BL,BUF2
SUB A
2、L,BL
JNC GREAT
NEG AL
GREAT:MOV RESULT,AL
EXIT: MOV AH,4CH
INT 21H
CODE ENDS
END START
②.編寫一段程序,已知BUF單元中有一無符號字節(jié)數(shù)據(jù)X,假設為8,根據(jù)以下函數(shù)關系編寫程序求Y的值,結果存入RESULT 單元。Z=5X X<10,X-5 X>=10;
DATA SEGMENT
BUF DB 8
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
STA
3、RT:MOV AX,DATA
MOV DS,AX
MOV AL,BUF
CMP AL,10
JAE GRE
MOV BL,AL
ADD AL,AL
ADD AL,AL
ADD AL,BL
JMP DONE
GRE: SUB AL,5
DONE: MOV RESULT,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
③.在內存單元BUF中存放一個帶符號字節(jié)數(shù)據(jù)X,
4、假定為-2,試根據(jù)以下函數(shù)關系編寫程序求Y的值,結果存入RESULT 單元。Y=1 X>0,0 X=0,-1 X<0;
DATA SEGMENT
BUF DB -2
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AL,BUF
CMP AL,0
JGE L1
MOV AL,-1
JMP L3
L1:JZ L2
MOV AL,1
JMP L3
L2:MOV AL,0
5、
L3:MOV RESULT,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
2. N個數(shù)中求最大值、最小值.假定N=10,已知原始數(shù)據(jù)存放在BUF開始的內存單元中,將結果存入MAX,MIN內存單元中。
DATA SEGMENT
BUF DB 3,5,7,8,5,3,9,7,13,1
COUNT EQU $-BUF
MAX DB ?
MIN DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX
6、,DATA
MOV DS,AX
MOV CX,COUNT-1
MOV AL,BUF
MOV MAX,AL
MOV MIN,AL
LEA SI,BUF
AGAIN:
MOV AL,[SI+1]
CMP AL,MIN
JGE S1
MOV MIN,AL
S1: CMP AL,MAX
JLE S2
MOV MAX,AL
S2: INC SI
LOOP AGAIN
MOV AH,4CH
INT 21H
CODE ENDS
END START
7、
3. 編寫程序求1+2+3+……+N<100時最大的N值,將N值送NUM單元中,同時將1+2+3+……+N的和送到SUM單元中。
DATA SEGMENT
NUM DB ?
SUM DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AL,0
MOV BL,0
AGAIN:INC BL
ADD AL,BL
CMP AL,100
JB AGAIN
SU
8、B AL,BL
DEC BL
MOV NUM,BL
MOV SUM,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
4. 統(tǒng)計字符,正數(shù),負數(shù),零的個數(shù)。
①.若自STRING單元開始存放一個字符串,以'$'結尾,試編寫程序,
統(tǒng)計字符串的長度,并將結果存入COUNT單元。
DATA SEGMENT
STRING DB 'abcdefg$'
COUNT DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:
9、DATA
START:MOV AX,DATA
MOV DS,AX
LEA SI,STRING
MOV CX,0
NEXT: MOV AL,[SI]
CMP AL,'$'
JZ DONE
INC CX
INC SI
JMP NEXT
DONE: MOV COUNT,CX
MOV AH,4CH
INT 21H
CODE ENDS
END START
②.自BUF單元開始存放10個帶符號字節(jié)數(shù)據(jù),將其中的正數(shù)、負數(shù)和零選出來,并統(tǒng)
10、計其個數(shù),分別存入PLUS、MINUS和ZERO單元中。
DATA SEGMENT
BUF DB 5,-2,0,-1,4,0,-4,8,0,-7
PLUS DB ?
MINUS DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:DATA,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA SI,BUF
MOV CX,10
AGAIN:MOV AL,[BX]
INC BX
AND AL,AL
JS M1
11、 JZ M2
INC PLUS
JMP NEXT
M1: INC MINUS
JMP NEXT
M2: INC ZERO
JMP NEXT
NEXT: LOOP AGAIN
MOV AH,4CH
INT 21H
CODE ENDS
END START
5. 求壓縮BCD碼的和。已知從BUF1和BUF2單元開始,存放兩個各為10個字節(jié)的BCD數(shù),求這兩個數(shù)的和,并將結果存入BUF3單元中。
DATA SEGMENT
BUF1 DB 01H,01H,01H,01H,0
12、1H,01H,01H,01H,01H,01H
BUF2 DB 03H,03H,03H,03H,03H,03H,03H,03H,03H,03H
BUF3 DB 11 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CX,10
LEA SI,BUF1
LEA DI,BUF2
LEA BX,BUF3
AGAIN:
MOV AL,[SI]
ADC AL,[DI]
13、 DAA
MOV [BX],AL
INC SI
INC DI
INC BX
LOOP AGAIN
ADC AH,0
MOV [BX],AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
6. 8255編程題:(課后實驗)
8255工作于方式0,此時PA、PB、PC均為可獨立輸入/輸出的并行口。8255的各寄存器對應的口地址為:PA口:200H,PB口:202H,PC口:204H,控制口:206H。要求8255工作于方式0,PA口設置為輸入,PC口
14、設置為輸出。
DATA SEGMENT
C8255 EQU 206H
P8255A EQU 200H
P8255C EQU 204H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,C8255 ;設置為A口輸入,C口輸出
MOV AL,90H
OUT DX,AL
BG: MOV DX,P8255A ;將A口狀態(tài)從C口輸出
IN AL,DX
MOV DX,P8255C
OUT DX,AL
JMP BG
CODE ENDS
END START
6
題目a