用汇编语言编写:从键盘输入一个正的奇数,按照值打印出菱形图案,如输入7,则输出如下图案(需有输入错误提示和重新输入的提示) * *** ***** ******* ***** *** *
时间: 2023-12-06 15:03:34 浏览: 84
```assembly
.model small
.stack 100h
.data
msg1 db 0dh,0ah,'Please input an odd number: $'
msg2 db 0dh,0ah,'Invalid input, please input an odd number: $'
msg3 db 0dh,0ah,'Press any key to continue...$'
num db ?
.code
main proc
mov ax, @data
mov ds, ax
call get_num
call print_diamond
mov ah, 4ch
int 21h
main endp
get_num proc
mov ah, 9
lea dx, msg1
int 21h
mov ah, 1
int 21h
sub al, 30h
cmp al, 0
jle input_error
cmp al, 9
jg input_error
cmp al, 1
je input_error
and al, 1
jz input_error
mov num, al
ret
input_error:
lea dx, msg2
mov ah, 9
int 21h
call get_num
ret
get_num endp
print_diamond proc
mov cx, num
mov bx, 1
mov dx, 0
print_top:
call print_space
call print_star
inc bx
cmp bx, cx
jle print_top
mov bx, cx
mov dx, 1
print_bottom:
call print_space
call print_star
dec bx
cmp bx, 1
jge print_bottom
ret
print_space proc
push cx
mov cx, dx
shr cx, 1
space_loop:
mov ah, 2
mov dl, ' '
int 21h
loop space_loop
pop cx
dec dx
ret
print_space endp
print_star proc
push cx
mov cx, bx
star_loop:
mov ah, 2
mov dl, '*'
int 21h
loop star_loop
pop cx
add dx, 2
ret
print_star endp
end main
```
阅读全文
相关推荐










