汇编王爽老师,16.3 计算正弦sin值的直接定址表

  按照课本程序,并且补充了角度值取到 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,效果如下:
在这里插入图片描述
谢谢阅读

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值