1.将键盘输入的大写转换成小写
DATA SEGMENT
BUF DB 'ERROR!',0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,01H;读入字符
INT 21H
CMP AL,'a'
JB NEXT;如果读入字符小于a转
CMP AL,'z'
JA NEXT;如果读入字符大于z转
AND AL,11011111B;小写字母转换成大写
MOV DL,AL;输出到屏幕
MOV AH,02H
INT 21H
JMP DONE
NEXT: LEA DX,BUF;报错
MOV AH,09H
INT 21H
DONE: MOV AH,4CH;返回DOS
INT 21H
CODE ENDS
END START
2.实现
DATA SEGMENT
BUF DB ;实际运行时设为三个数,如1 2 3 得到结果3
Y DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,BUF ;指针SI初始化
MOV AL,[SI]
CMP AL,[SI+1] ;比较X1和X2
JNC NEXT
MOV AL,[SI+1]
NEXT: INC SI
CMP AL,[SI+1] ;AL与X3比较
JNC NEXT1
MOV AL,[SI+1]
NEXT1: MOV Y,AL ;送结果
MOV AH,4CH
INT 21H
CODE ENDS
END START
3.比较三个无符号数的大小
DATA SEGMENT
BUF DB 'A','B','C';
K DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
START: PUSH DS
MOV AX,0
PUSH AX
MOV AX,DATA
MOV DS,AX
LEA SI,BUF ;指针SI初始化
MOV AL,[SI]
CMP AL,[SI+1] ;比较A和B
JE BJ1
MOV AL,[SI+1]
CMP AL,[SI+2] ;比较B和C
JE NEXT1
JMP BJ2
BJ1: MOV AL,[SI+1]
CMP AL,[SI+2]
JE NEXT2;三个都相等
JMP NEXT1;只有A、B相等
BJ2: MOV AL,[SI]
CMP AL,[SI+2]
JE NEXT1;只有A、C相等
JMP NEXT0;三个都不相等
NEXT0: MOV AL,'0'
MOV K,AL
JMP EXIT
NEXT1: MOV AL,'1'
MOV K,AL
JMP EXIT
NEXT2: MOV AL,'2'
MOV K,AL
EXIT: MOV DL,K
MOV AH,02H
INT 21H
RET
MAIN ENDP
CODE ENDS
END START
4.编写一个能实现下列表达式的程序
DATA SEGMENT
BUF DB A,B,C;实际运行时设为三个数,如1 2 3 得到结果3
N DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,BUF ;指针SI初始化
MOV AL,[SI]
CMP AL,[SI+1] ;比较X1和X2
JB NEXT
MOV AL,[SI]
SUB AL,[SI+1]
ADD AL,[SI+2]
MOV N,AL
JMP DONE
NEXT: MOV AL,[SI]
ADD AL,[SI+1]
MOV N,AL
JMP DONE
DONE: MOV AH,4CH
INT 21H
CODE ENDS
END START
5.比较两个字符串
DATA SEGMENT
STRING1 DB 'ABcdEFGH'
STRING2 DB 'ABcDEFGH'
RESULT DW (?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV CX,8
LEA SI,STRING1
LEA DI,STRING2
REPZ CMPSB
JNZ LAB;遇到了不同字符,ZF为0,转到LAB
MOV RESULT,0
JMP EXIT
LAB:
MOV AX,8
SUB AX,CX
MOV RESULT,AX
EXIT: MOV AH,4CH
INT 21H
CODE ENDS
END START
6.输入两个十进制数,做加法后输出
DATA SEGMENT
MESS1 DB 0dh,0ah,'INPUT THE FIRST NUMBER:','$'
MESS2 DB 0dh,0ah,'INPUT THE SECOND NUMBER:','$'
BUF1 DB 10,0,10 DUP(?)
BUF2 DB 10,0,10 DUP(?)
BUF3 DB 0dh,0ah,'THE SUM IS:'
BUF4 DB 3 DUP(?),'$'
DATA ENDS
STACK1 SEGMENT 'STACK'
DB 100 DUP(?)
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK1
START PROC FAR
PUSH DS
MOV AX,0
PUSH AX
MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESS1;输入提示信息
MOV AH,9
INT 21H
MOV DX,OFFSET BUF1;读入第一个数
MOV AH,0AH
INT 21H
MOV DX,OFFSET MESS2;再次输入提示信息
MOV AH,9
INT 21H
MOV DX,OFFSET BUF2;读入第二个数
MOV AH,0AH
INT 21H
MOV AL,[BUF1+3]
AND AL,0FH
MOV BL,[BUF2+3]
AND BL,0FH
ADD AL,BL
AAA
PUSHF;保存CF
OR AL,30H
MOV [BUF4+2],AL
MOV AL,[BUF1+2]
AND AL,0FH
MOV BL,[BUF2+2]
AND BL,0FH
POPF
ADC AL,BL
AAA
PUSHF
OR AL,30H
MOV [BUF4+1],AL
MOV AL,'0'
POPF
ADC AL,0
MOV [BUF4],AL
MOV DX,OFFSET BUF3
MOV AH,9
INT 21H
RET
START ENDP
CODE ENDS
END START