微机原理与接口技术设计实验
- 格式:doc
- 大小:44.50 KB
- 文档页数:12
实验一:编写程序,比较两个字符串STRING1和STRING2所含的字符是否相同,若字符相同则显示“Match”,否则显示“No Match”
参考程序:
DATA SEGMENT
STRING1 DB 'HAPPY ASM'
LEN EQU $-STRING1
STRING2 DB 'HAPPY ASM'
MESSAGE1 DB 'MATCH',0DH,0AH,'$'
MESSAGE2 DB 'NO MATCH',0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STRING1
LEA DI,STRING2
MOV CX,LEN
COMPARE:
MOV AL,[SI]
MOV BL,[DI]
CMP AL,BL
JNE DISMATCH
INC SI
INC DI
LOOP COMPARE
MATCH:LEA DX,MESSAGE1
JMP DISP
DISMATCH:LEA DX,MESSAGE2
DISP: MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
实验二:编写程序,从键盘输入一串字符,以‘$’或回车结束,将其中的小写字母转变为大写字母,其余字符不做转换,原样输出,结果显示在屏幕上。
参考程序:
DATA SEGMENT
BUF DB 50
DB ?
DB 50 DUP(?)
INPUTSTRING DB 'PLEASE INPUT A STRING:','$' OUTPUTSTRING DB 'OUTPUTSTRING IS:','$' ENTERSTRING DB 0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA DX,INPUTSTRING
MOV AH,09H
INT 21H
LEA DX,BUF
MOV AH,0AH
INT 21H
LEA DX,ENTERSTRING
MOV AH,09H
INT 21H
LEA BX,BUF
ADD BX,2
NEXT1:MOV AL,[BX]
INC BX
COMPARE:CMP AL,24H
JZ DISP
CMP AL,61H
JB NEXT1
CMP AL,7AH
JA NEXT1
SUB AL,20H
MOV [BX-1],AL
JMP NEXT1
DISP:LEA DX,OUTPUTSTRING
MOV AH,09H
INT 21H
LEA DX,BUF+2
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
实验三:利用子程序方法编写程序,设有10个无符号数的字节序列,查找该序列中的最大值和最小值,并把结果显示在屏幕上。
参考程序1:(针对一位10进制数)
STACK SEGMENT STACK
DW 256 DUP(?)
TOP LABEL WORD
STACK ENDS
DATA SEGMENT
BUF DB 00H,01H,02H,03H,04H
DB 05H,06H,07H,08H,09H
COUNT EQU $-BUF
ENTERSTRING DB 0DH,0AH,'$'
MAXSTRING DB 'THE MAXIMUN NUMBER IS:','$'
MINSTRING DB 'THE MINIMUN NUMBER IS:','$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
LEA SP,TOP
MOV SI,OFFSET BUF
MOV CX,COUNT
CALL BRANCH
PUSH AX
LEA DX,MAXSTRING
MOV AH,09H
INT 21H
POP AX
MOV DL,AH
ADD DL,30H
PUSH AX
MOV AH,02H
INT 21H
LEA DX,ENTERSTRING
MOV AH,09H
INT 21H
LEA DX,MINSTRING
MOV AH,09H
INT 21H
POP AX
MOV DL,AL
ADD DL,30H
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
BRANCH PROC NEAR
JCXZ NEXT4
PUSH SI
PUSH CX
PUSH BX
MOV BH,[SI]
MOV BL,BH
CLD
NEXT1: LODSB
CMP AL,BH
JBE NEXT2
MOV BH,AL
JMP NEXT3
NEXT2: CMP AL,BL
JAE NEXT3
MOV BL,AL
NEXT3: LOOP NEXT1
MOV AX,BX
POP BX
POP CX
POP SI
NEXT4: RET
BRANCH ENDP
CODE ENDS
END START
参考程序二:(针对两位十六进制数或无符号数)