📄 work4.asm
字号:
data segment
n dw ?
spn dw 0 ;每行之前要输出空格数
isOutput db 0; ;每行之前是否输出过空格,1为输出过,否则为0
two db 2
tip db "Input number of the first line:(1~9) $"
tip1 db "Out of range,input again: $"
data ends
stack1 segment para stack
dw 20h dup(0)
stack1 ends
code segment
assume cs:code, ds:data, ss:stack1
start:
mov ax,data
mov ds,ax
mov dx,offset tip
mov ah,09h
int 21h
jmp en
re: mov dl,0dh ;换行
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
mov dx,offset tip1
mov ah,09h
int 21h
en: mov ah,01h
int 21h
sub al,30h
cmp al,1 ;输入超出范围(1-9),回跳
jb re
cmp al,9
ja re
test al,01h ;测试al的奇偶
jne next ;是奇数,则不用加1
inc al ;偶数加1
next: mov ah,0
mov n,ax
mov dl,0dh ;换行
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
mov ax,n
inc ax
div two
mov ah,0
mov cx,ax ;输出行数为2*(n+1)
lop1: push cx
mov cx,n
lop2: push cx
mov cx,spn
cmp isOutput,1
je ns
jcxz ns
lop3: mov dl,20h ;每行之前输出的空格
mov ah,02h
int 21h
loop lop3
mov isOutput,1 ;该行已经输出空格
ns: pop cx
mov dl,'*'
mov ah,02h
int 21h
mov dl,20h ;输出空格
mov ah,02h
int 21h
loop lop2
mov dl,0dh ;换行
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
mov isOutput,0 ;新一行没输出空格
sub n,2 ;每行输出"*"的个数计数
add spn,2 ;每行之前输出空格计数
pop cx
loop lop1
mov ah,4ch
int 21h
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -