📄 16bit乘以16bit.asm
字号:
;---------------------------------------------------------------------
; ;16位*16位乘法子程序
;时间:2004年7月
;单位: 上海凌阳科技
;作者:周俊峰
;Email:zhoujf@sunplus.com.cn
;Tel:021-50804488 ext.6124
;
; ;16位*16位乘法子程序
;入口参数:G_Faciend_Buffer,G_Faciend_Buffer+1
; G_Multiplier_Buffer,G_Multiplier_Buffer+1
;
;出口参数:G_Mul_Result,G_Mul_Result+1,G_Mul_Result+2,G_Mul_Result+3
;----------------------------------------------------------------------
.SYNTAX 6502 ;process standard 6502 addressing syntax
.LINKLIST ;generate linklist information
.SYMBOLS ;generate symbolic debug information
.PAGE0 ;define values in the range from 00h to FFh
.include SPMC810A.inc
ORG $80
G_Faciend_Buffer DS 2;被乘数
G_Multiplier_Buffer DS 2;乘数
G_Mul_Result DS 4;结果
G_LoopTimes DS 1
.CODE
ORG $EE00
.PUBLIC V_Reset
V_Reset:
V_PowerOn:
sei
ldx #C_STACK_BOTTOM ;set stack bottom
txs ; transfer x to stack
;======================================================================
lda #B8H
sta G_Faciend_Buffer;装入被乘数低位数据
lda #0BH
sta G_Faciend_Buffer+1;装入被乘数高位数据
lda #B8H
sta G_Multiplier_Buffer;装入乘数低位数据
lda #0BH
sta G_Multiplier_Buffer+1;装入乘数高位数据
lda #0;清除结果单元
sta G_Mul_Result
sta G_Mul_Result+1
sta G_Mul_Result+2
sta G_Mul_Result+3
lda #16
sta G_LoopTimes ;set loop times
L_Mul_Loop:
clc
rol G_Multiplier_Buffer ;乘数向左移一位,判断最高位是‘0’还是‘1’
rol G_Multiplier_Buffer+1
bcc L_Maximal_Bit0 ;c=0 ;if C is not "1" jump to L_Maximal_Bit0
L_Maximal_Bit1: ;结果加上faciend被乘数;32位加16位数
clc
lda G_Mul_Result
adc G_Faciend_Buffer
sta G_Mul_Result
lda G_Mul_Result+1
adc G_Faciend_Buffer+1
sta G_Mul_Result+1
lda G_Mul_Result+2;加进位
adc #0
sta G_Mul_Result+2
lda G_Mul_Result+3;加进位
adc #0
sta G_Mul_Result+3
L_Maximal_Bit0: ;left move the result directly
clc
rol G_Mul_Result
rol G_Mul_Result+1
rol G_Mul_Result+2
rol G_Mul_Result+3
dec G_LoopTimes
lda G_LoopTimes
bne L_Mul_Loop
;right move the result
clc
ror G_Mul_Result+3
ror G_Mul_Result+2
ror G_Mul_Result+1
ror G_Mul_Result
;========================================================================
MainLoop:
nop
nop
nop
lda G_Mul_Result
lda G_Mul_Result+1
lda G_Mul_Result+2
lda G_Mul_Result+3
nop
nop
nop
jmp MainLoop
;=============================================================================
; Interrupt Subroutine
;=============================================================================
V_IRQ:
PHA
TXA
PHA
IRQ_END:
PLA
TAX
PLA
RTI
;=====================================================
;Description: NMI Interrupt Vector
;=====================================================
.PUBLIC V_NMI
V_NMI:
RTI
.ORG $1FFA ;Define two different areas since SICE
DW V_NMI ;FMay download program emulated either
DW V_PowerOn ;FIn internal memory or external memory
DW V_IRQ
.ORG $7FFA ;For EPROM with EV BRD. IRQ. CPU, or EXT. CPU
DW V_NMI
DW V_PowerOn
DW V_IRQ
.ORG $FFFA ;For ICE trace.
DW V_NMI
DW V_PowerOn
DW V_IRQ
.END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -