题目一:编写一程序,比较两个字符串所含字符是否相等,如果相等,在屏幕上显示“Y”,反之显示“N”。
DATAS SEGMENT
CUE1 DB 'PLEASE INPUT A STRING:$'
CUE2 DB 'PLEASE INPUT ANOTHER STRING:$'
BUFF1 DB 10 H DUP ( '$' )
BUFF2 DB 10 H DUP ( '$' )
NEWLINE DB 13 , 10 , '$'
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
ASSUME CS: CODES, DS: DATAS, SS: STACKS
START:
MOV AX, DATAS
MOV DS, AX
MOV ES, AX
; 9 号输出字符串
MOV DX, OFFSET CUE1 ; 没有偏移,因为输出常量字符串
MOV AH, 9
INT 21 H
; 10 号输入字符串
LEA DX, BUFF1
MOV AH, 0 AH
INT 21 H
; 输出换行
LEA DX, NEWLINE
MOV AH, 9
INT 21 H
LEA DX, CUE2
MOV AH, 9
INT 21 H
LEA DX, BUFF2
MOV AH, 0 AH
INT 21 H
MOV AH, 9
MOV DX, OFFSET NEWLINE
INT 21 H
MOV CL, BUFF1+ 1
CMP CL, BUFF2+ 1
JNE OUTPUT_N
MOV SI, OFFSET BUFF1+ 1
MOV DI, OFFSET BUFF2+ 1
CLD
REPE CMPSB
JE OUTPUT_Y
OUTPUT_N:
MOV AH, 9 ;
MOV DX, OFFSET NEWLINE ;
INT 21 H
MOV AH, 2
MOV DL, 'N'
INT 21 H
JMP HALT
OUTPUT_Y:
MOV AH, 9 ;
MOV DX, OFFSET NEWLINE ;
INT 21 H ;
MOV AH, 2
MOV DL, 'Y'
INT 21 H
JMP HALT
HALT:
MOV AX, 4 C00H
INT 21 H
CODES ENDS
END START
题目二:从键盘输入任意一串小写字符(字符个数可变),将输入的小写字符转换为相应的大写字符,并在显示器上显示输出。
DATAS SEGMENT
BUF DB 20 H DUP ( '$' )
NEWLINE DB 13 , 10 , '$'
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
ASSUME CS: CODES, DS: DATAS, SS: STACKS
START:
MOV AX, DATAS
MOV DS, AX
LEA DX, BUF
MOV AH, 0 AH
INT 21 H
MOV CL, BUF+ 1 ; cl中保存输入字符串实际的个数
XOR CH, CH
MOV SI, 2 ; 偏移2 个字节
LOP: MOV BL, BUF[ SI]
SUB BL, 20 H
MOV BUF[ SI] , BL
INC SI
LOOP LOP
MOV AH, 9
MOV DX, OFFSET NEWLINE
INT 21 H
MOV AH, 9
MOV DX, OFFSET BUF+ 2
INT 21 H
MOV AH, 4 CH
INT 21 H
CODES ENDS
END START