汇编程序设计:数字方阵程序

程序说明:
该程序实现显示一个数字的方阵,程序中的清屏功能可将上次运行的结果
清除,重新显示下次运行结果。本程序在dos中或windows98中运行。
流程图:
在这里插入图片描述
源代码:

data  segment
buf1  db '1  2  38  9  47  6  5'
buf2  db '1  2  3  412 13 14 511 16 15 610 9  8  7'
buf3  db '1  2  3  4  516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9'
dbuf  db 14 dup(?)
i1    db 0dh,0ah,'this is a fangzhen programme'
      db 0dh,0ah,'input q to exit'
      db 0dh,0ah,'Please input a number(3--5):','$'
i2    db 0dh,0ah,'input error,please reinput!','$'
n     db ?
b     db 1
data  ends
stack segment
      db 100 dup(?)
stack ends
code  segment
      assume ds:data,cs:code,ss:stack
main: 
      mov ax,data
      mov ds,ax
      call clear
lop:  lea dx,i1
      mov ah,9
      int 21h
      mov ah,1
      int 21h
      cmp al,'q'
      jz quit
      lea si,buf1
      mov n,7
      mov cl,3
      call clear
      cmp al,'3'
      jz  s
      lea si,buf2
      mov n,10
      mov cl,4
      cmp al,'4'
      jz  s
      lea si,buf3
      mov cl,5
      mov n,13
      cmp al,'5'
      jz s
      lea dx,i2
      mov ah,9
      int 21h
      call clear
      jmp lop
s:    
      mov bl,n
      lea di,dbuf
l:    mov al,[si]
      mov [di],al
      inc si
      inc di
      dec bl
      jne l
      mov [di],byte ptr '$'
      mov ah,2
      mov dh,b
      mov dl,0
      int 10h
      lea dx,dbuf
      mov ah,9
      int 21h
      inc b
      loop s
      
      jmp lop
quit: mov ah,4ch
      int 21h
;***清屏***
clear proc near
      push ax
      push bx
      push cx
      push dx
      mov  ah,6
      mov al,0
      mov ch,0
      mov cl,0
      mov dh,24
      mov dl,79
      mov bh,7
      int 10h
      pop dx
      pop cx
      pop bx
      pop ax
      ret
clear endp
code  ends
      end main

main.asm的代码

data  segment
buf1  db '1  2  38  9  47  6  5'
buf2  db '1  2  3  412 13 14 511 16 15 610 9  8  7'
buf3  db '1  2  3  4  516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9'
dbuf  db 14 dup(?)
i1    db 0dh,0ah,'this is a fangzhen programme'
      db 0dh,0ah,'input q to exit'
      db 0dh,0ah,'Please input a number(3--5):','$'
i2    db 0dh,0ah,'input error,please reinput!','$'
n     db ?
b     db 1
data  ends
stack segment
      db 100 dup(?)
stack ends
code  segment
      assume ds:data,cs:code,ss:stack
main: 
      mov ax,data
      mov ds,ax
      call clear
lop:  lea dx,i1
      mov ah,9
      int 21h
      mov ah,1
      int 21h
      cmp al,'q'
      jz quit
      lea si,buf1
      mov n,7
      mov cl,3
      call clear
      cmp al,'3'
      jz  s
      lea si,buf2
      mov n,10
      mov cl,4
      cmp al,'4'
      jz  s
      lea si,buf3
      mov cl,5
      mov n,13
      cmp al,'5'
      jz s
      lea dx,i2
      mov ah,9
      int 21h
      call clear
      jmp lop
s:    
      mov bl,n
      lea di,dbuf
l:    mov al,[si]
      mov [di],al
      inc si
      inc di
      dec bl
      jne l
      mov [di],byte ptr '$'
      mov ah,2
      mov dh,b
      mov dl,0
      int 10h
      lea dx,dbuf
      mov ah,9
      int 21h
      inc b
      loop s
      
      jmp lop
quit: mov ah,4ch
      int 21h
code  ends
      end main

clear.asm代码:

data  segment
buf1  db '1  2  38  9  47  6  5'
buf2  db '1  2  3  412 13 14 511 16 15 610 9  8  7'
buf3  db '1  2  3  4  516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9'
dbuf  db 14 dup(?)
i1    db 0dh,0ah,'this is a fangzhen programme'
      db 0dh,0ah,'input q to exit'
      db 0dh,0ah,'Please input a number(3--5):','$'
i2    db 0dh,0ah,'input error,please reinput!','$'
n     db ?
b     db 1
data  ends
stack segment
      db 100 dup(?)
stack ends
code  segment
      assume ds:data,cs:code,ss:stack
clear proc near
      push ax
      push bx
      push cx
      push dx
      mov  ah,6
      mov al,0
      mov ch,0
      mov cl,0
      mov dh,24
      mov dl,79
      mov bh,7
      int 10h
      pop dx
      pop cx
      pop bx
      pop ax
      ret
clear endp
code  ends
      end main

程序功能
主程序功能为根据输入的字符(数字)确定输出方阵,当输入’q’时,退出程序;否则,当输入数字为3~5之间整数时,输出对应维数的方阵,并跳至接收输入的部分等待下次输入。
类似于C语言中的switch - case - break结构。
子程序CLEAR的功能为清屏(滚屏)。具体实现为通过调用10H号函数库中6号子函数进行滚屏操作。

参数传递
本题中主程序-子程序间不存在参数传递,子程序的作用仅为清屏。

中断向量及中断处理函数位置计算
中断向量:
本题用到了10H、21H函数库的函数调用,入口地址为0:40h ,0:84h。
10H号函数库:CS=410h+2h=42h , IP=410h=40h 。中断向量为0:40H。
21H号函数库:CS=421h+2h=86h , IP=421h=84h 。中断向量为0:84h。

猜你喜欢

转载自blog.csdn.net/hairi1234/article/details/85571711