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

程序说明:
该程序实现显示一个数字的方阵,程序中的清屏功能可将上次运行的结果
清除,重新显示下次运行结果。本程序在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。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞行模式HR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值