Languages: 汇编
Categories: 编程语言基础
The experiment2(改进版).txt
DATA SEGMENT
CHAR1 DB 20
DB 0
DB 20 DUP(0)
CHAR2 DB 'The number of the char you want to count is:$' CHAR3 DB 'INPUT THE CHAR YOU WANT TO COUNT:$'

DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,CHAR1
MOV AH,0AH
INT 21H
MOV AH,1
INT 21H
LEA DX,CHAR3
MOV AH,9
INT 21H

MOV AH,01H
INT 21H

MOV DX,0H
MOV CX,0H
LEA BX,CHAR1+2
MOV CL,CHAR1+1
COUNT:
MOV DL,[BX]
CMP DL,AL
JNZ NEXT
INC DH
NEXT:
INC BX
LOOP COUNT

CALL ENDLINE
MOV CH,DH
LEA DX,CHAR2
MOV AH,9
INT 21H

CALL ENDLINE
DISPCOUNT:
MOV AL,CH
MOV AH,0H
MOV BL,10
DIV BL
MOV BH,AH
MOV AH,00H

MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,BH

MOV DL,AL
MOV AH,02H
INT 21H

MOV AH,4CH
INT 21H

ENDLINE PROC
PUSH DX
MOV AH,02H
MOV DL,0DH
INT 21H
MOV AH,02H
MOV DL,0AH
INT 21H
POP DX
RET
CODE ENDS

END START


The experiment3.txt
；//‘由于输入数选用的是DB数据类型，所以只能处理8位有符号数，即-127~127'
；//‘程序采用的是冒泡排序法按从小到大的顺序排序，所以程序执行完之后，找到原来待排序数据的地址就能查看最大最小值’
DATA SEGMENT
NUM DB 10,1,2,9,5,-8,45,-99,127
SUM DB \$-NUM-1

DATA ENDS
STACK1 SEGMENT STACK

STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA BX,NUM
MOV CL,[SUM]
MOV DH,CL
MOV AX,0H
CIRO:;//THE SURROUNDING LOOP
MOV CL,DH
LEA BX,NUM
CIRI:;//THE INNER LOOP
MOV AL,[BX]
MOV DL,1[BX]
CMP AL,DL
JG CHG
INC BX
LOOP CIRI;TIL
CIEXIT:
MOV CL,DH
DEC DH
LOOP CIRO;TSL

MOV AH,4CH;PROGRAM EXIT
INT 21H

CHG:
MOV [BX],DL
INC BX
MOV [BX],AL
LOOP CIRI
JMP CIEXIT

CODE ENDS
END START