第一题
是DATA SEGMENT
INPUT DB 4
DB ?
DB 4 DUP (?)
DB '$'
NUM DW 20 DUP(?)
AVE DB ?
OUTPUT1 DB 'INPUT A NUMBER',0DH,0AH,'$'
OUTPUT2 DB 'INPUT AGAIN(END WITH #)',0DH,0AH,'$'
OUTPUT3 DB 'AVERAGE IS:','$'
DATA ENDS
;----------------
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
PUSH DS
XOR AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
START:MOV DX,OFFSET OUTPUT1
MOV AH,9
INT 21H
MOV BL, 0
MOV DI,OFFSET NUM
MOV DX,OFFSET INPUT
MOV AH,0AH
INT 21H
MOV DX,OFFSET INPUT+2
MOV AH,9
INT 21H
MOV SI,OFFSET INPUT+1
MOV CL,[SI]
INC SI
MOV CH,0
CALL ADECXB
MOV [DI],AX
INC BL
INC DI
INC DI
INN: MOV DX,OFFSET OUTPUT2
MOV AH,9
INT 21H
MOV DX,OFFSET INPUT
MOV AH,0AH
INT 21H
MOV SI,OFFSET INPUT+1
MOV CL,[SI]
INC SI
CMP BYTE PTR [SI],'#'
JZ DONE
MOV CH, 0
CALL ADECXB
MOV [DI],AX
INC BL
INC DI
INC DI
JMP INN
DONE: MOV DX, 0
PUSH BX
MOV DI,OFFSET NUM
R: MOV AX,[DI]
ADD DX,AX
INC DI
INC DI
DEC BL
CMP BL,0
JNZ R
MOV AX,DX
MOV DX,OFFSET OUTPUT3
PUSH AX
MOV AH,9
INT 21H
POP AX
POP BX
DIV BL
MOV AH,0
MOV BL,100
DIV BL
MOV BH,AL
ADD BH,30H
MOV DL,BH
PUSH AX
MOV AH,2
INT 21H
POP AX
MOV AL,AH
MOV AH,0
MOV BL,10
DIV BL
ADD AL,30H
MOV DL,AL
PUSH AX
MOV AH,2
INT 21H
POP AX
ADD AH,30H
MOV DL,AH
MOV AH,2
INT 21H
RET
MAIN ENDP
;-------------
ADECXB PROC
PUSH BX
PUSH CX
PUSH DX
PUSH SI
MOV BH,0
XOR AX,AX
AGAIN:ADD AX,AX
MOV DX,AX
ADD AX,AX
ADD AX,AX
ADD AX,DX
MOV BL,[SI]
AND BL,0FH
ADD AX,BX
INC SI
LOOP AGAIN
POP SI
POP DX
POP CX
POP BX
RET
ADECXB ENDP
CODE ENDS
END MAIN