📄 imth08.asm
字号:
********************************************************************************
*
* Filename: IMTH08.ASM
* Revision: 1.00
* Date: February 24, 1993
*
* Written By: Mark Johnson
* Motorola CSIC Applications
*
* Assembled Under: P&E Microcomputer Systems IASM08 (Beta Version)
*
* ********************************
* * Revision History *
* ********************************
*
* Revision 1.00 2/24/93 Original Source
********************************************************************************
*
*
* Program Description:
*
* This program contains six* integer math routines for the 68HC08 family
* of microcontrollers.
*
* *Note: 1) The 32 x 16 Unsigned divide algorithm was based on
* the one written for the 6805 by Don Weiss and was
* modified to return a 32-bit quotient.
* 2) The Table lookup and interpolation algorithm was
* based on the one written by Kevin Kilbane and was
* modified to interpolate both positive and negative
* slope linear functions.
*
*
********************************************************************************
*
* Start of main routine
*
*
ORG $50 ;RAM address space
*
INTACC1 RMB 4 ;32-bit integer accumulator #1
INTACC2 RMB 4 ;32-bit integer accumulator #2
SPVAL RMB 2 ;storage for stack pointer value
*
*
ORG $6E00 ;ROM/EPROM address space
START LDHX #$450 ;load H:X with upper RAM boundary + 1
TXS ;move stack pointer to upper RAM boundary
CLRH ;clear H:X
********************************************************************************
* Unsigned 16x16 multiply
*
* This routine multiplies the 16-bit unsigned number stored in
* locations INTACC1:INTACC1+1 by the 16-bit unsigned number stored in
* locations INTACC2:INTACC2+1 and places the 32-bit result in locations
* INTACC1....INTACC1+3 (INTACC1 = MSB.....INTACC1+3 = LSB).
*
********************************************************************************
UMULT16 EQU *
PSHA ;save acc
PSHX ;save x-reg
PSHH ;save h-reg
AIS #-6 ;reserve six bytes of temporary
;storage on stack
CLR 6,SP ;zero storage for multiplication carry
*
* Multiply (INTACC1:INTACC1+1) by INTACC2+1
*
LDX INTACC1+1 ;load x-reg w/multiplier lsb
LDA INTACC2+1 ;load acc w/multiplicand lsb
MUL ;multiply
STX 6,SP ;save carry from multiply
STA INTACC1+3 ;store lsb of final result
LDX INTACC1 ;load x-reg w/multiplier msb
LDA INTACC2+1 ;load acc w/multiplicand lsb
MUL ;multiply
ADD 6,SP ;add carry from previous multiply
STA 2,SP ;store 2nd byte of interm. result 1.
BCC NOINCA ;check for carry from addition
INCX ;increment msb of interm. result 1.
NOINCA STX 1,SP ;store msb of interm. result 1.
CLR 6,SP ;clear storage for carry
*
* Multiply (INTACC1:INTACC1+1) by INTACC2
*
LDX INTACC1+1 ;load x-reg w/multiplier lsb
LDA INTACC2 ;load acc w/multiplicand msb
MUL ;multiply
STX 6,SP ;save carry from multiply
STA 5,SP ;store lsb of interm. result 2.
LDX INTACC1 ;load x-reg w/multiplier msb
LDA INTACC2 ;load acc w/multiplicand msb
MUL ;multiply
ADD 6,SP ;add carry from previous multiply
STA 4,SP ;store 2nd byte of interm. result 2.
BCC NOINCB ;check for carry from addition
INCX ;increment msb of interm. result 2.
NOINCB STX 3,SP ;store msb of interm. result 2.
*
* Add the intermediate results and store the remaining three bytes of the
* final value in locations INTACC1....INTACC1+2.
*
LDA 2,SP ;load acc with 2nd byte of 1st result
ADD 5,SP ;add acc with lsb of 2nd result
STA INTACC1+2 ;store 2nd byte of final result
LDA 1,SP ;load acc with msb of 1st result
ADC 4,SP ;add w/ carry 2nd byte of 2nd result
STA INTACC1+1 ;store 3rd byte of final result
LDA 3,SP ;load acc with msb from 2nd result
ADC #0 ;add any carry from previous addition
STA INTACC1 ;store msb of final result
*
* Reset stack pointer and recover original register values
*
AIS #6 ;deallocate the six bytes of local
;storage
PULH ;restore h-reg
PULX ;restore x-reg
PULA ;restore accumulator
RTS ;return
********************************************************************************
********************************************************************************
*
* Unsigned 32 x 32 Multiply
*
* This routine multiplies the unsigned 32-bit number stored in locations
* INTACC1.....INTACC1+3 by the unsigned 32-bit number stored in locations
* INTACC2.....INTACC2+3 and places the unsigned 64-bit result in locations
* INTACC1.....INTACC2+3 (INTACCC1 = MSB ..... INTACC2+3 = LSB).
*
********************************************************************************
UMULT32 EQU *
PSHA ;save acc
PSHX ;save x-reg
PSHH ;save h-reg
CLRX ;zero x-reg
CLRA ;zero accumulator
AIS #-35T ;reserve 35 bytes of temporary storage
;on stack
TSX ;transfer stack pointer + 1 to H:X
AIX #32T ;add number of bytes in storage table
STHX SPVAL ;save end of storage table value
AIX #-32T ;reset H:X to stack pointer value
*
* Clear 32 bytes of storage needed to hold the intermediate results
*
INIT CLR ,X ;xero a byte of storage
INCX ;point to next location
CPHX SPVAL ;check for end of table
BNE INIT ;
*
* Initialize multiplicand and multiplier byte position pointers,
* temporary storage for carry from the multiplication process, and
* intermediate storage location pointer
*
STA 35T,SP ;zero storage for multiplication carry
LDA #3 ;load acc w/ 1st byte position
STA 33T,SP ;pointer for multiplicand byte
STA 34T,SP ;pointer for multiplier byte
TSX ;transfer stack pointer + 1 to H:X
AIX #7 ;position of 1st column in storage
STHX SPVAL ;pointer to interm. storage position
CLRH ;clear h-reg
*
* Multiply each byte of the multiplicand by each byte of the multiplier
* and store the intermediate results
*
MULTLP LDX 33T,SP ;load x-reg w/multiplicand byte pointer
LDA INTACC2,X ;load acc with multiplicand
LDX 34T,SP ;load x-reg w/ multiplier byte pointer
LDX INTACC1,X ;load x-reg w/ multiplier
MUL ;multiply
ADD 35T,SP ;add carry from previous multiply
BCC NOINC32 ;check for carry from addition
INCX ;increment result msb
NOINC32 STX 35T,SP ;move result msb to carry
LDHX SPVAL ;load x-reg w/ storage position pointer
STA ,X ;store intermediate value
AIX #-1 ;decrement storage pointer
STHX SPVAL ;store new pointer value
CLRH ;clear h-reg
DEC 34T,SP ;decrement multiplier pointer
BPL MULTLP ;multiply all four bytes of multiplier
;by one byte of the multiplicand
LDHX SPVAL ;load x-reg w/ storage position pointer
LDA 35T,SP ;load acc w/ carry (msb from last mult)
STA ,X ;store msb of intermediate result
AIX #!11 ;add offset for next intermediate
;result starting position
STHX SPVAL ;store new value
CLRH ;clear h-reg
CLR 35T,SP ;clear carry storage
LDX #3 ;
STX 34T,SP ;reset multiplier pointer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -