- 开发环境:masm for Windows
- 大端模式
如果结果过大(ah不为0)输出N结束
否则输出
Y
结果对应的ascll码的字符
结果的10进制数
(10进制倒序输出的版本:)
DATAS SEGMENT
;此处输入数据段代码
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
;此处输入代码段代码
mov ax,0
mov cx,5
lo:
add ax,cx
dec cx
jcxz endlo
jmp lo
endlo:
mov ch,0
mov cl,ah
mov bl,al
jcxz yes
mov ah,02h
mov dl,'N'
int 21h
mov dl,10
int 21h
MOV AH,4CH
INT 21H
yes:
mov dh,0
mov ah,02h
mov dl,'Y'
int 21h
mov dl,10
int 21h
;输出结果的ascll码+'0'
mov dl,bl
add dl,'0'
int 21h
mov dl,10
int 21h ;回车
;输出10进制整数bl
mov ch,0
mov bh,10
echof:
mov ah,0
mov al,bl
div bh
;ah为余数 al为商
mov bl,al
mov dl,ah
mov ah,02h
add dl,'0'
int 21h
mov cl,bl
jcxz endecho
jmp echof
endecho:
MOV AH,4CH
INT 21H
CODES ENDS
END START
(利用堆栈对10进制重新排序的版本:)
DATAS SEGMENT
db 0,0,0
;此处输入数据段代码
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
;此处输入代码段代码
mov ax,0
mov cx,5
lo:
add ax,cx
dec cx
jcxz endlo
jmp lo
endlo:
mov ch,0
mov cl,ah
mov bl,al
jcxz yes
mov ah,02h
mov dl,'N'
int 21h
mov dl,10
int 21h
MOV AH,4CH
INT 21H
yes:
mov dh,0
mov ah,02h
mov dl,'Y'
int 21h
mov dl,10
int 21h
;输出结果的ascll码+'0'
mov dl,bl
add dl,'0'
int 21h
mov dl,10
int 21h ;回车
;输出10进制整数bl
mov ch,0
mov bh,10
echof:
mov ah,0
mov al,bl
div bh
;ah为余数 al为商
mov bl,al
mov dl,ah
mov ah,02h
add dl,'0'
int 21h
mov cl,bl
jcxz endecho
jmp echof
endecho:
MOV AH,4CH
INT 21H
CODES ENDS
END START