16.3 直接定址表
本帖最后由 sbx 于 2020-9-18 20:36 编辑;编写一个子程序,计算sin(x),x∈{00,300,600,900,1200,1500,1800},
;并在屏幕中间显示计算结果。
;用ax向子程序传递角度。
assume cs:code
code segment
start:
mov ax,121
call showsin
mov ax,4c00h
int 21h
showsin:
jmp short show
table1 dw 0,30,60,90,120,150,180
table2 dw ag0,ag30,ag60,ag90,ag120,ag150,ag180;字符串偏移地址表
ag0 db '0',0 ;sin(0)对应的字符串"0"
ag30 db '0.5',0 ;sin(30)对应的字符串"0.5"
ag60 db '0.866',0;sin(60)对应的字符串"0.866"
ag90 db '1',0 ;sin(90)对应的字符串"1"
ag120 db '0.866',0;sin(120)对应的字符串"0.866"
ag150 db '0.5',0 ;sin(150)对应的字符串"0.5"
ag180 db '0',0 ;sin(180)对应的字符串"0"
err db 'error',0
show:
push bx
push es
push si
push cx
push di
mov bx,0b800h
mov es,bx
;检测提供的角度值是否在table1表中,不在则退出,在则继续
mov si,0
mov cx,7
s1:cmp ax,table1
jne s
jmp short s2
s:add si,2
loop s1
mov si,0
mov di,160*12+40*2
s5:mov al,err
cmp al,0
jne s3
jmp short s4
s3:
mov es:,al
inc si
add di,2
jmp short s5
s4:
pop di
pop cx
pop si
pop es
pop bx
ret
;si就是table2的偏移,取得对应的字符串的偏移地址,放在bx中
s2:
mov bx,table2
;以下显示sin(x)对应的字符串
mov si,160*12+40*2
shows: mov ah,cs:
cmp ah,0
je showret
mov es:,ah
inc bx
add si,2
jmp short shows
showret:
pop di
pop cx
pop si
pop es
pop bx
ret
code ends
end start
页:
[1]