📄 exp43.asm
字号:
res_hm .usect "flt_add",1 ;result high mantissa
res_lm .usect "flt_add",1 ;result low mantissa
res_exp .usect "flt_add",1 ;result exponent
res_sign .usect "flt_add",1 ; result sign
op2_hm .usect "flt_add",1 ; OP2 high mantissa
op2_lm .usect "flt_add",1 ; OP2 low mantissa
op2_se .usect "flt_add",1 ; OP2 sign and exponent
op1_se .usect "flt_add",1 ; OP1 sign and exponent
op1_hm .usect "flt_add",1 ; OP1 high mantissa
op1_lm .usect "flt_add",1 ; OP1 low mantissa
op1_msw .usect "flt_add",1 ; OP1 packed high word
op1_lsw .usect "flt_add",1 ; OP1 packed low word
op2_msw .usect "flt_add",1 ; OP2 packed high word
op2_lsw .usect "flt_add",1 ; OP2 packed low word
err_no .usect "flt_add",1 ;
*******************************************************************
* Floating point number 12.0 can be represented as 1100 = 1.100 x 23 => sign =0
* biased exponent = 127+3 = 130
* 130 = 10000010
* Mantissa 10000000000000000000000
* Thus 12.0 can be represented as 01000001010000000000000000000000= 4140h
**********************************************************************************
*
K_OP1_HIGH .set 4140h ; floating point number 12.0
K_OP1_LOW .set 0000h
K_OP2_HIGH .set 4140h ; floating point number 12.0
K_OP2_LOW .set 0000h
.def start
.mmregs
.text
start: RSBX C16 ; Insure long adds
LD #res_hm,DP ; initialize the page pointer
LD #K_OP2_HIGH,A ; load floating #2 – 12
STL A,op2_msw
LD #K_OP2_LOW,A
STL A,op2_lsw
LD #K_OP1_HIGH,A ; load floating #1 – 12
STL A,op1_msw
LD #K_OP1_LOW,A
STL A,op1_lsw
;store result sign
ld op1_msw,A
and #8000h,a
ld op2_msw,b
and b,a
bc sign_0,AEQ
st #1,res_sign
b next
sign_0: st #0,res_sign
;store op1
next: dld op1_msw,a
bc op_zero,AEQ
stl a,op1_lm
sth a,-7,op1_se
and #07fh,16,a
or #80h,16,a
sth a,op1_hm
;store op2
dld op2_msw,a
bc op_zero,AEQ
stl a,op2_lm
sth a,-7,op2_se
and #07fh,16,a
or #80h,16,a
sth a,op2_hm
;以下逻辑要验证
;caculate expont
LD op1_se,A ; Load OP1 sign and exponent
AND #0FFh,A ; Mask OP1 exponent
LD op2_se,B ; Load OP2 sign and exponent
AND #0FFh,B ; Mask OP2 exponent
SUB #07Fh,B ; Subtract offset (avoid double bias)
ADD B,A ; Add OP1 exponent
STL A,res_exp ; Save result exponent on stack
;caculate mantissa,32bit unsigned fract multiply
ld #0,a
LD op1_lm,T ; load low mant of op1 to T register
MPYU op2_lm,A ; RS * YZ
MPYU op2_hm,B ; RS * 0X
add a,-16,b
ld op1_hm,t
mpyu op2_lm,a
add b,a
mpyu op2_hm,b
stl b,res_hm ;low word of 0X*0Q
add res_hm,16,a;
sfta a,8,b
bc step1,nc
ld a,-1,a;shift right (>=2)
ld res_exp,b
add #1,b
STL b,res_exp ; Save result exponent on stack
step1
ld res_exp,b
BC underflow,BLT ; branch to underflow handler if exp < 0
SUB #0FFh,b ; test for overflow
BC overflow,BGT ; branch to overflow is exp > 255
cmant
stl a,-7,res_lm
ld a,-7,a
ld a,-16,a
and #7fh,a
stl a,res_hm
here
b here
op_zero:st #0,res_sign
st #0,res_hm
st #0,res_lm
st #0,res_exp
b here
overflow
st #0ffh,res_exp
b cmant
underflow
st #0,res_exp
b cmant
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -