?? basic_op.asm
字號:
.mmregs
.include "basic_op.inc"
.global _add
.global _sub
.global _abs_s
.global _shl
.global _shr
.global _mult
.global _L_mult
.global _negate
.global _extract_h
.global _extract_l
.global _round
.global _L_mac
.global _L_msu
.global _L_macNs
.global _L_add
.global _L_sub
.global _L_add_c
.global _L_sub_c
.global _L_negate
.global _mult_r
.global _L_shl
.global _L_shr
.global _shr_r
.global _mac_r
.global _msu_r
.global _L_deposit_l
.global _L_shr_r
.global _L_abs
.global _L_sat
.global _norm_s
.global _norm_l
.global _div_s
.bss _Overflow,1
.bss _Carry,1
.bss _Error,1
.global _Overflow
.global _Carry
.global _Error
.text
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 add(Word16 var1,Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_add:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx c16
ssbx sxm
sSBX OVM
ld #0,b
LD a,15,a
LD A,1,A
ADD *SP(3),16,A
NOP
nop
xc 1,AOV
LD #1,B
STL B,*(_Overflow)
LD A,-16,A
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 sub(Word16 var1,Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_sub:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx c16
ssbx sxm
sSBX OVM
ld #0,b
LD a,15,a
LD A,1,A
sub *SP(3),16,A
NOP
nop
xc 1,AOV
LD #1,B
STL B,*(_Overflow)
LD A,-16,A
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;abs_s(x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_abs_s:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx c16
ssbx sxm
ssbx ovm
ld A,15,A
LD A,1,A
ABS A
LD A,-16,A
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 shl(Word16 var1,Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_shl:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
ssbx ovm
ssbx c16
st #0,*(_Overflow)
ld *sp(3),b
ld a,15,a
ld a,1,a
; and #8000h,b
bc shl_R,blt ;檢驗左移還是右移
; ld *sp(3),b
and #0fff0h,b ;檢驗是否大于15
bc shl_DO,beq
ld a,8,a
ld a,8,a
b shl_O
shl_DO:
ld *sp(3),b
and #0fff8h,b
bc shl_FDO,beq
ld a,8,a
bc shl_O,aov
ld *sp(3),b
sub #8h,b
stl b,*sp(3)
shl_FDO:
ld *sp(3),asm
ld a,asm,a
bc shl_O,aov
b shl_E
shl_R:
ld *sp(3),b
and #0fff0h,b
xor #0fff0h,b
bc shl_RDO,beq
ld a,-16,a
b shl_E
shl_RDO:
ld *sp(3),asm
ld a,asm,a
b shl_E
shl_O:
st #1,*(_Overflow)
shl_E:
ld a,-16,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;shr(x,y)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_shr:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
ssbx ovm
ssbx c16
st #0,*(_Overflow)
ld *sp(3),16,b
neg b
ld b,-16,b
stl b,*sp(3) ;取負數(shù)
ld a,15,a
ld a,1,a
and #8000h,b
bc shr_R,bneq ;檢驗左移還是右移
ld *sp(3),b
and #0fff0h,b ;檢驗是否大于15
bc shr_DO,beq
ld a,8,a
ld a,8,a
b shr_O
shr_DO:
ld *sp(3),b
and #0fff8h,b
bc shr_FDO,beq
ld a,8,a
bc shr_O,aov
ld *sp(3),b
sub #8h,b
stl b,*sp(3)
shr_FDO:
ld *sp(3),asm
ld a,asm,a
bc shr_O,aov
b shr_E
shr_R:
ld *sp(3),b
and #0fff0h,b
xor #0fff0h,b
bc shr_RDO,beq
ld a,-16,a
b shr_E
shr_RDO:
ld *sp(3),asm
ld a,asm,a
b shr_E
shr_O:
st #1,*(_Overflow)
shr_E:
ld a,-16,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 mult(Word16 var1, Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_mult:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx c16
SSBX FRCT
ssbx sxm
ssbx ovm ; to allow -1* -1 (1)
ld #0,b
STLM A,t
MPY *SP(3),A
LD A,-16,A
xc 1,aov
ld #1,b
stl b,*(_Overflow)
POPM ST1
POPM ST0
RETE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_mult(Word16 var1,Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_mult:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
SSBX FRCT
ssbx sxm
ssbx c16
ssbx ovm ; to allow -1* -1 (1)
ld #0,b
STLM A,t
MPY *SP(3),A
xc 1,aov
ld #1,b
stl b,*(_Overflow)
POPM ST1
POPM ST0
RETE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 negate(Word16 var1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_negate:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx ovm
ssbx sxm
ssbx c16
ld a,15,a
ld a,1,a
neg a
ld a,-16,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;extract_h(x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_extract_h:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
rsbx ovm
ld a,-16,a
POPM ST1
POPM ST0
RETE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;extract_l(L_x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_extract_l:
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word16 round(Word32 L_x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_round:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx ovm
ssbx sxm
ld #0,b
add #4000h,1,a
xc 1,aov
ld #1,b
stl b,*(_Overflow)
ld a,-16,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_mac(Word32 L_var3, Word16 var1, Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_mac:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
SSBX FRCT
ssbx sxm
ssbx ovm
st #0,*(_Overflow)
ld *sp(3),t
mac *sp(4),a
ld a,b
nop
xc 2,aov
st #1,*(_Overflow)
ld b,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_msu(Word32 L_var3, Word16 var1, Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_msu:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
SSBX FRCT
ssbx sxm
ssbx ovm
st #0,*(_Overflow)
ld *sp(3),t
mas *sp(4),a
ld a,b
nop
xc 2,aov
st #1,*(_Overflow)
ld b,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_macNs(Word32 L_var3, Word16 var1, Word16 var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_macNs:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
SSBX FRCT
ssbx sxm
ssbx ovm
st #0,*(_Overflow)
ld *sp(3),t
mac *sp(4),a
nop
nop
xc 2,aov
st #1,*(_Overflow)
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_add(Word32 L_var1, Word32 L_var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_add:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
ssbx ovm
dld *sp(3),b
add a,b
st #0,*(_Overflow)
xc 2,bov
st #1,*(_Overflow)
ld b,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_sub(Word32 L_var1, Word32 L_var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_sub:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
ssbx ovm
dld *sp(3),b
sub b,a
ld a,b
st #0,*(_Overflow)
xc 2,aov
st #1,*(_Overflow)
ld b,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_add_c(Word32 L_var1, Word32 L_var2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_add_c:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
Rsbx ovm
dld *sp(3),b
add a,b
ld *(_Carry),t
st #0,*(_Overflow)
st #0,*(_Carry)
xc 2,bov
st #1,*(_Overflow)
xc 2,c
st #1,*(_Carry)
ldm t,a
add a,b
nop
nop
xc 2,bov
st #1,*(_Overflow)
xc 2,c
st #1,*(_Carry)
ld b,a
POPM ST1
POPM ST0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Word32 L_sub_c(Word32 L_var1, Word32 L_var2)
;無借位時,carry置1,借位時,置0。
;carry為1,說明未被借位,不用減1,否則,減1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_L_sub_c:
PSHM ST0
PSHM ST1
RSBX OVA
RSBX OVB
ssbx sxm
Rsbx ovm
ld #1,b
sub *(_Carry),b
stlm b,t
dld *sp(3),b
sub b,a
ld a,b
st #0,*(_Overflow)
st #1,*(_Carry)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -