⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhaoyue0506.asm

📁 该程序可以实现数据的接收、排序并显示
💻 ASM
字号:
         .MODEL SMALL    ;define memory model
         .STACK 16       ;define stack segment
         .DATA           ;define data segment
SPACE DB 1000 DUP (' ')  ;定义一个空格并重复一千次
;定义一系列字符串----------------------------------------------------------------------
ZHOU1  DB 0DH,0AH,'The number you have input is:','$'           ;定义回车,换行和字符串
KEYORDER  DB 0DH,0AH,'1 key : Order the number from max to min',0DH,0AH
          DB '2 key : Turn the number from min to max',0DH,0AH
          DB '3 key : Show the numbers you have input',0DH,0AH
          DB 'c key : Exit',0DH,0AH,'$'
pwait     DB 'wait me a second please',0DH,0AH,'$'              ;定义字符串,回车,换行
enter     DB  0DH,0AH,'please enter the arrary:',0DH,0AH,'$'    ;定义字符串,回车,换行
disp      DB 'result is below',0DH,0AH,'$'                      ;定义字符串,回车,换行
QUIT      DB 0BH,0AH,'BYE BYE!!!!!!','$'
nub       DB 0
buf       DB 10 DUP (?)     ;定义10个存储空间用于存储数据
DBUFFER   DB 8 DUP (':')    ;定义冒号并重复8次
aver      DB 0
          .CODE             ;define code segment
          ORG 100H          ;伪指令,定义起始地址为100h
;--------------------------------------------------------------------------------------
;主过程--------------------------------------------------------------------
MAIN      PROC NEAR                 ;main part of program
          MOV AX,@data              ;数据段附加段初始化
          MOV DS,AX
          MOV ES,AX
          MOV AX,0001H              ;(ah)=00h
          INT 10H                   ;设置显示方式,(al=01h)40*25 16色文本
          MOV BP,OFFSET SPACE       ;得到SPACE的偏移地址,存入基址指针寄存器
          MOV DX,0B00H              ;dh/dl=起始行/列
          MOV CX,1000               ;(ch)=字符串长度
          MOV BX,0030H              ;背景颜色和字体颜色的设置
          MOV AX,1300H              ;(ah)=13h
          INT 10H                   ;显示字符串
;---------------------------------------------------------------------------
;将buf中的所有空间清零以便后面跳回来-----------------------
back:     MOV CX,000AH
          LEA BX,BUF    ;取得buf的偏移地址
          MOV AL,00H    ;把00h赋给al用于后面清零
loop1:    MOV [BX],AL
          INC BX
          LOOP loop1    ;所有存储空间全部清零
          ;-------------------------------------------------          
          MOV AH,09H         ;显示字符串
          LEA DX,keyorder    ;取得keyorder的偏移地址
          INT 21H            ;显示keyorder标号处定义的字符串
;-----------------------------------------------------------
keyin:    MOV AH,02H     ;显示输出
          MOV DL,0DH
          INT 21H        ;输出回车
          MOV AH,02H
          MOV DL,0AH
          INT 21H        ;输出换行
          MOV AH,01H     ;键盘输入并回显      
          INT 21H
          ;把从键盘输入的数与1,2,3,c进行比较      
          CMP AL,'1'
          JE maxtomin    ;如果输入的是1,则跳转到maxtomin
          CMP AL,'2'
          JE mintomax    ;如果输入的是2,则跳转到mintomax
          CMP AL,'3'
          JE shownub     ;如果输入的是3,则跳转到shownub
          CMP AL,'c'
          JE byebye      ;如果输入的是c,则跳转到byebye
          JMP keyin      ;子程序调用结束后重新从键盘输入数据
;---------------------------------------------
;子程序调用-----------------------------------
shownub:
          CALL shownubp     ;调用求输入数字的个数子程序     
          JMP back          ;返回到back

maxtomin:  
          CALL maxtominp    ;调用从大到小排练子程序
          JMP back          ;返回到back

mintomax:
          CALL mintomaxp    ;调用从小到大排列子程序
          JMP back          ;返回到back

byebye:   MOV ah,09h
          LEA DX,QUIT
          INT 21h
          MOV DX,0B00H      ;dh/dl=起始行/列
          MOV CX,280        ;(ch)=字符串长度
          MOV BX,003EH      ;页号以及背景颜色和字体颜色的设置
          MOV AX,1301H      ;(ah)=13h
          INT 10H           ;显示字符串
          MOV AH,02H        ;(ah)=02h
          MOV DX,1801H      ;dh/dl=行/列
          MOV BH,0          ;定义页号
          INT 10H           ;置光标位置
          MOV ax,4c00h      ;(ah)=4ch
          INT 21h           ;带返回码终止,(al)=返回码
main      endp   
;---------------------------------------------------
;接受数据子过程-------------------------------------
rec       proc near
          mov di,0        ;附加段偏移地址为0
          lea bx,buf      ;取得buf的偏移地址
newchar:  mov ax,0100h    ;(ah)=01h
          int 21h         ;调用输入中断
          ;输入的字符与空格、回车和数值进行比较
          cmp al,20h      ;空格跳到保存数据
          je save       
          cmp al,0dh      ;回车跳出子过程
          je exit
          sub al,30h      ;输入数据转换成16进制
          xchg al,dl      ;交换al与dl,即(al)清零
          mov cl,0ah      ;(cl)=0ah
          mul cl          ;(ax)=(al)*(cl)
          xchg al,dl
          add dl,al
          jmp newchar     ;跳回输入
save:     inc ch 
          mov [bx],dl
          add di,word ptr [bx]
          inc bx
          mov dx,0000h
          jmp newchar
exit:     inc ch
          mov [bx],dl
          add di,word ptr [bx]
          mov ax,di
          div ch
          mov aver,al
          mov [aver+1],ah
          mov ah,02h
          mov dl,0ah
          int 21h
          mov nub,ch
          xor ch,ch
          ret
rec       endp
;-----------------------------------------
;排序子过程------------------------------
;从大到小排列
paixu     proc near
          MOV Cl,nub
          mov ch,0
one:      lea bx,buf
          PUSH CX 
two:      MOV AX,[BX] 
          CMP AL,AH 
          JC four
three:    INC BX 
          LOOP two
          POP CX 
          LOOP one
          ret 
four:     XCHG AL,AH 
          MOV [BX],AX 
          JMP three
paixu     endp
;----------------------------------------------------
;从小到大排列
paixu2    proc near
          MOV Cl,nub
          mov ch,0
one2:     lea bx,buf 
          PUSH CX 
two2:     MOV AX,[BX] 
          CMP AL,AH 
          Jae four2
three2:   INC BX 
          LOOP two2
          POP CX 
          LOOP one2
          ret 
four2:    XCHG AL,AH 
          MOV [BX],AX 
          JMP three2
paixu2     endp
;----------------------------------------------------
;把buf的内容按10进制显示-------------------------------
disply  proc near
        MOV cx,10    ;循环10次             
        LEA bx,buf        
loop2:  MOV al,[bx]
        CMP al,0     ;是0就不必考虑了
        je isz
        ;是小于9的数字就不要考虑100与10位的数字
        cmp al,9
        jbe only0
        jmp next
only0:  mov ah,al
        jmp only1         
next:   mov ah,00h
        ;--------------------------
        ;百位数输出
        mov dh,100
        div dh
        push ax
        add al,30h
        mov ah,02h
        mov dl,al
        cmp dl,30h    ;为0跳过输出
        je a1        
        int 21h
        ;--------------------------
        ;十位数输出
a1:     pop ax     
        xchg ah,al
        and ax,00ffh
        mov dh,10
        div dh
        push ax
        add al,30h
        mov ah,02h
        mov dl,al           
        int 21h
        ;---------------------------
        ;个位数输出
a2:     pop ax
only1:  add ah,30h
        mov dl,ah
        mov ah,02h                
        int 21h
        ;---------------------------
        mov ah,02h
        MOV dl,' ' 
        INT 21h
isz:    INC bx
        AND ax,0000h    ;对ax清零        
        LOOP loop2
        RET
disply  endp
;----------------------------------
;------------------------------------
shownubp  proc near
        MOV ah,09h
        LEA dx,zhou1
        INT 21h
        MOV ah,02h
        MOV dl,nub
        ADD dl,30h
        INT 21h
        RET
shownubp endp
;------------------------------------
mintomaxp proc near
          MOV ax,0900h     ;提示输入
          LEA dx,enter
          INT 21h
          ;------------------
          MOV dl,00h
          CALL rec        ;调用接收子过程
          ;------------------
          MOV dx,offset pwait
          MOV ax,0900h    ;提示等待
          INT 21h
          ;------------------
          CALL paixu2     ;调用排序子过程
          ;-------------------
          MOV ax,0900h    ;提示输出正确顺序
          LEA dx,disp
          INT 21h
          CALL disply
          ;-------------------
          MOV ah,02h
          MOV dl,0dh
          INT 21h
          MOV ah,02h
          MOV dl,0ah
          INT 21h         ;回车换行
          ;-------------------
          RET
mintomaxp endp
maxtominp proc near
          MOV ax,0900h    ;提示输入
          LEA dx,enter  
          INT 21h
          ;------------------
          MOV dl,00h
          CALL rec        ;调用接收子过程
          ;------------------
          MOV dx,offset pwait
          MOV ax,0900h    ;提示等待
          INT 21h
          ;------------------
          CALL paixu      ;调用排序子过程
          ;-------------------
          MOV ax,0900h    ;提示输出正确顺序
          LEA dx,disp
          INT 21h
          CALL disply
          ;-------------------
          MOV ah,02h
          MOV dl,0dh
          INT 21h
          MOV ah,02h
          MOV dl,0ah
          INT 21h         ;回车换行
          ;-------------------
          RET
maxtominp ENDP
END main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -