``````DATA segment
BUF1 DB '0613'
BUF2 DB 1,2,3,4,5,6,7,8,9,0,1,2,3
NUM1 DB 4 DUP(?)
NUM2 DB 2 DUP(?)

DATA ENDS;
CODE segment
ASSUME  CS :CODE,DS :DATA
START:

MOV si,3
MOV CX,4
TAPEIN:
MOV AH,01H
INT 21H
MOV BL,30H
SUB AL,BL
MOV NUM1[si],AL
DEC si
LOOP TAPEIN     ;输入4个数字，存入num1

MOV si,3
MOV DH,0
MOV AH,0
CAL:
MOV BX,3        ;将0613与输入的数字一一比较
CAL1:
MOV AL,NUM1[si]
MOV DL,BUF1[BX]
CMP AL,DL
JE EQUAL        ;发现有相等的则比较是不是同一个地方
UNEQUAL:
DEC BX          ;不相等则BX减一直到0
CMP BX,0
JAE CAL1
DEC si          ;比较
CMP si,0
JAE CAL
MOV NUM2+1,DH
MOV NUM2,AH
JMP PRINTF

EQUAL:          ;有相等元素
cmp si,BX
JNE CALB        ;但不是同一个地方
INC DH          ;是同一个地方
DEC si
JMP CAL

CALB:
INC AH
DEC si
JMP CAL

PRINTF:         ;输出提示句式
MOV AH,2
MOV DL,NUM2+1
INT 21H

MOV AH,2
MOV DL,'A'
INT 21H

MOV AH,2
MOV DL,NUM2
INT 21H

MOV AH,2
MOV DL,'B'
INT 21H

CMP NUM2+1,4        ;全对个数不是4则重新输入
JNE  START

mov dl,0ah          ;输出换行
mov ah,02h
int 21h

mov   bx,0
MOV CX,13
OVERPRINT:
MOV DL,BUF2[BX]
MOV AH,2H
INT 21H
INC BX
LOOP    OVERPRINT          ;输出学号

CODE ENDS
END START
``````

1个回答