按照课本程序,并且补充了角度值取到 0 30 60 90 120 150 180 以外值的判断。课本让自己完成,所以就自己构思然后完成了。经过对-10 160 200 150 的验证,程序可以正常输出结果:显示对应的正弦值或显示“angle not right”
assume cs:code
code segment
main:
mov ax,-10
call show
mov ax,4c00h
int 21h
show:
jmp shgo
error db 'angle not right',0
table dw ag0,ag30,ag60,ag90,ag120,ag150,ag180
ag0 db '0',0
ag30 db '0.5',0
ag60 db '0.866',0
ag90 db '1',0
ag120 db '0.866',0
ag150 db '0.5',0
ag180 db '0',0
shgo:
cmp ax,0
jb sherror
cmp ax,180
ja sherror
push ax
push bx
mov bl,30
div bl
cmp ah,0
pop bx
pop ax
jne sherror
push ax
push bx
push es
push si
push di
mov bx,0b800h
mov es,bx
mov di,160 * 12 + 40 * 2
mov bl,30
div bl
mov bl,al
add bl,bl
mov bh,0
mov si,table[bx]
mov bh,2eh
shlp:
mov bl,cs:[si]
cmp bl,0
je shok
mov es:[di],bx
inc si
add di,2
jmp shlp
shok:
pop di
pop si
pop es
pop bx
pop ax
ret
sherror:
push si
push di
push bx
mov bx,0b800h
mov es,bx
mov si,0;
mov di,160 * 12 + 40 * 2
mov bh,2eh
erlp:
cmp error[si],0
je erok
mov bl, error[si]
mov es:[di],bx
inc si
add di,2
jmp erlp
erok:
pop bx
pop di
pop si
ret
code ends
end main
当角度值为-10时候
改变角度值为150,效果如下:
谢谢阅读