📄 humaoming.asm
字号:
;宏calldos定义
calldos macro function
mov ah,function
int 21h
endm; 宏calldos结束
; 宏crlf定义
crlf macro
mov dl,0dh ; 回车
calldos 2 ; 2号功能调用---显示字符
mov dl,0ah ; 换行
calldos 2
endm ; 宏crlf结束
;定义数据段
data segment
;提示信息字符串
message db 'please input 10 numbers:',0dh,0ah,'$'
;定义缓冲区
kb_buf db 3 ;定义可接受最大字符数
actlen db ? ;实际输入的字符数
buffer db 3 dup(?);输入的字符放在此区域中
;数据及统计结果
numbers db 10 dup(?);键入的数据转换成二进制后放在此处
le59 db 0 ; 0-59的个数
ge60 db 0 ;60-79的个数
ge80 db 0 ;80-99的个数
;显示结果的字符串
sortstr db 'sorted numbers:'
sortnum db 10 dup(20h,20h,','),0dh,0ah
mess00 db '0-59:',30h,30h,0dh,0ah
mess60 db '60-79:',30h,30h,0dh,0ah
mess80 db '80-99:',30h,30h,0dh,0ah,'$'
data ends ;数据段结束
;定义代码段
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
;1.显示提示信息
lea dx,message
mov ah,9
int 21h
;
mov cx,10 ;共读入十个数据
lea di,numbers ;设置数据保存区指针
;2.从键盘读入一个数据,转换成二进制数存入DI所指的内存单元
lp1:lea dx,kb_buf
mov ah,0ah
int 21h
mov al,[buffer]
sub al,30h
shl al,4
add al,[buffer+1]
sub al,30h
mov [di],al
inc di ; 指向下一个数据单元
crlf ; 在下一行输入
loop lp1 ; 直到10个数据都输入完
;3.排序
lea di,numbers
mov bl,9
next1:mov si,di
mov cl,bl
next2:mov al,[si]
inc si
cmp al,[si]
jc next3
mov dl,[si]
mov [si-1],dl
mov [si],al
next3:dec cl
jnz next2
dec bl
jnz next1
;4.统计
mov cx,10
lea si,numbers
again:mov al,[si]
cmp al,60h
jnc nnext1
inc [le59]
jmp sto
nnext1:cmp al,80h
jnc nnext2
inc [ge60]
jmp sto
nnext2:inc [ge80]
sto:inc si
loop again
;5.转换ASCII码存入SORTNUM
lea si,numbers
lea di,sortnum
mov bl,10
nnnext:mov al,[si]
mov dl,al
mov cl,4
shr al,cl
add al,30h
mov [di],al
mov al,dl
and al,0fh
add al,30h
mov [di+1],al
inc si
inc di
inc di
inc di
dec bl
jnz nnnext
;6.统计结果转化
mov al,[le59]
mov dl,al
mov cl,4
shr al,cl
add [mess00+5],al
mov al,dl
and al,0fh
add [mess00+6],al
mov al,[ge60]
mov dl,al
mov cl,4
shr al,cl
add [mess60+6],al
mov al,dl
and al,0fh
add [mess60+7],al
mov al,[ge80]
mov dl,al
mov cl,4
shr al,cl
add [mess80+6],al
mov al,dl
and al,0fh
add [mess80+7],al
lea dx,sortstr ;显示排序和统计的结果
mov ah,9
int 21h
mov ah,4ch ;返回DOS
int 21h
code ends ;代码段结束
end start ;程序结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -