《微機(jī)原理編程題【參照內(nèi)容】》由會(huì)員分享,可在線閱讀,更多相關(guān)《微機(jī)原理編程題【參照內(nèi)容】(6頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、
微機(jī)原理編程題
1. 分支程序設(shè)計(jì)
①.編寫(xiě)一段程序,已知BUF1單元中有一帶符號(hào)字節(jié)數(shù)據(jù)X,BUF2中有一帶符號(hào)字節(jié)數(shù)據(jù)Y,根據(jù)以下函數(shù)關(guān)系編寫(xiě)程序求Z的值,結(jié)果存入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
②.編寫(xiě)一段程序,已知BUF單元中有一無(wú)符號(hào)字節(jié)數(shù)據(jù)X,假設(shè)為8,根據(jù)以下函數(shù)關(guān)系編寫(xiě)程序求Y的值,結(jié)果存入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
③.在內(nèi)存單元BUF中存放一個(gè)帶符號(hào)字節(jié)數(shù)據(jù)X,
4、假定為-2,試根據(jù)以下函數(shù)關(guān)系編寫(xiě)程序求Y的值,結(jié)果存入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個(gè)數(shù)中求最大值、最小值.假定N=10,已知原始數(shù)據(jù)存放在BUF開(kāi)始的內(nèi)存單元中,將結(jié)果存入MAX,MIN內(nèi)存單元中。
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. 編寫(xiě)程序求1+2+3+……+N<100時(shí)最大的N值,將N值送NUM單元中,同時(shí)將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)計(jì)字符,正數(shù),負(fù)數(shù),零的個(gè)數(shù)。
①.若自STRING單元開(kāi)始存放一個(gè)字符串,以'$'結(jié)尾,試編寫(xiě)程序,
統(tǒng)計(jì)字符串的長(zhǎng)度,并將結(jié)果存入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單元開(kāi)始存放10個(gè)帶符號(hào)字節(jié)數(shù)據(jù),將其中的正數(shù)、負(fù)數(shù)和零選出來(lái),并統(tǒng)
10、計(jì)其個(gè)數(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單元開(kāi)始,存放兩個(gè)各為10個(gè)字節(jié)的BCD數(shù),求這兩個(gè)數(shù)的和,并將結(jié)果存入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編程題:(課后實(shí)驗(yàn))
8255工作于方式0,此時(shí)PA、PB、PC均為可獨(dú)立輸入/輸出的并行口。8255的各寄存器對(duì)應(yīng)的口地址為:PA口:200H,PB口:202H,PC口:204H,控制口:206H。要求8255工作于方式0,PA口設(shè)置為輸入,PC口
14、設(shè)置為輸出。
DATA SEGMENT
C8255 EQU 206H
P8255A EQU 200H
P8255C EQU 204H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,C8255 ;設(shè)置為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