给出dosbox画圆程序的主要部分,请优化此程序不再需要输入“”C”即可直接跳转到draw1处,并且使得该程序能够重复画圆, data segment shuc db 'draw a yuan: $' hua1 db 'input yuanxin and banjing(example:310,220 200): $' ; 提示用户输入圆心和半径 zifu db 20 dup(0) ; 用以临时存放输入字符 shu db 20 dup(0) ; 存放转换后的数字 suan db 24 dup(0) data ends stack segment stk db 16 dup(0) stack ends code segment assume cs:code, ds:data, ss:stack start: mov ax,data mov ds,ax mov ax,stack mov ss,ax mov dx,offset shuc ; 显示输入 C 的提示字符 call showmsg call input ; 输入字符 C 的处理 mov al,ds:[si] and al,11011111b ; 便于大小写都识别,将字符转换成大写 cmp al,43h je draw1 ; 如果输入字符为 C,则跳转到 draw1 处 ; 如果输入字符不为 C,则程序结束 mov ax,4c00h int 21h input: ; 实现键盘输入字符 mov bx,0 mov cx,20 re: mov ah,1h int 21h cmp al,0dh ; 0dh jz scx mov si,offset zifu mov [bx][si],al inc bx loop re ret scx: ; 条件跳转时对 cx 设置 mov cx,0 ret showmsg: ; 用来显示提示字符 mov ah,9h int 21h ret moshi: ; 屏幕显示模式 mov al,12h mov ah,0 int 10h ret zhuanshu: ; 将输入的 ASCII 码转为数字 mov bx,offset zifu mov bp,offset shu mov cx,16 mov si,0 mov di,0 lei: mov al,ds:[bx][si] cmp al,0 jz scx sub al,30h mov dl,100 mul dl mov word ptr ds:[bp][di],ax mov ax,0 mov al,ds:[bx][si+1] sub al,30h mov dl,10 mul dl add ax,word ptr ds:[bp][di] mov word ptr ds:[bp][di],ax mov ax,0 mov al,ds:[bx][si+2] sub al,30h add ax,word ptr ds:[bp][di] mov word ptr ds:[bp][di],ax add si,4 add di,2 loop lei ret draw1: mov dx,offset hua1 call showmsg call input call zhuanshu call moshi mov bx,offset shu mov ax,ds:[bx] mov si,ax mov ax,ds:[bx+2] mov di,ax call drawyuan mov ax,4c00h int 21h code ends end start
时间: 2024-02-01 14:04:16 浏览: 92
优化后的程序如下,实现了不需要输入“C”即可直接跳转到draw1处,并且能够重复画圆:
```
data segment
shuc db 'draw a yuan: $'
hua1 db 'input yuanxin and banjing(example:310,220 200): $'
zifu db 20 dup(0)
shu db 20 dup(0)
suan db 24 dup(0)
data ends
stack segment
stk db 16 dup(0)
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov dx,offset hua1 ; 显示输入圆心和半径的提示字符
call showmsg
call input
call zhuanshu
call moshi
mov bx,offset shu
mov ax,ds:[bx]
mov si,ax
mov ax,ds:[bx+2]
mov di,ax
call drawyuan
jmp start ; 重复画圆
input:
; 实现键盘输入字符
mov bx,0
mov cx,20
re:
mov ah,1h
int 21h
cmp al,0dh ; 0dh
jz scx
mov si,offset zifu
mov [bx][si],al
inc bx
loop re
ret
scx:
; 条件跳转时对 cx 设置
mov cx,0
ret
showmsg:
; 用来显示提示字符
mov ah,9h
int 21h
ret
moshi:
; 屏幕显示模式
mov al,12h
mov ah,0
int 10h
ret
zhuanshu:
; 将输入的 ASCII 码转为数字
mov bx,offset zifu
mov bp,offset shu
mov cx,16
mov si,0
mov di,0
lei:
mov al,ds:[bx][si]
cmp al,0
jz scx
sub al,30h
mov dl,100
mul dl
mov word ptr ds:[bp][di],ax
mov ax,0
mov al,ds:[bx][si+1]
sub al,30h
mov dl,10
mul dl
add ax,word ptr ds:[bp][di]
mov word ptr ds:[bp][di],ax
mov ax,0
mov al,ds:[bx][si+2]
sub al,30h
add ax,word ptr ds:[bp][di]
mov word ptr ds:[bp][di],ax
add si,4
add di,2
loop lei
ret
drawyuan:
; 画圆
mov cx,di
mov ax,si
sub cx,ax
shr cx,1
mov dx,di
mov bx,ax
add dx,bx
mov ax,di
sub ax,dx
neg ax
mov dx,ax
mov ax,si
sub ax,dx
mov di,cx
mov cx,ax
mov ax,bx
mov bx,di
mov ax,ax
mov cx,cx
mov dx,0
mov ah,0ch
int 10h
ret
code ends
end start
```
阅读全文