📄 imth08.asm
字号:
ROL REMAINDER+1 ;shift remainder lsb
ROL REMAINDER ;shift remainder msb
*
* Subtract both bytes of the divisor from the remainder
*
LDA REMAINDER+1 ;get remainder lsb
SUB 2,SP ;subtract divisor lsb from remainder lsb
STA REMAINDER+1 ;store new remainder lsb
LDA REMAINDER ;get remainder msb
SBC 1,SP ;subtract divisor msb from remainder msb
STA REMAINDER ;store new remainder msb
LDA DIVIDEND+3 ;get low byte of dividend/quotient
SBC #0 ;dividend low bit holds subtract carry
STA DIVIDEND+3 ;store low byte of dividend/quotient
*
* Check dividend/quotient lsb. If clear, set lsb of quotient to indicate
* successful subraction, else add both bytes of divisor back to remainder
*
BRCLR 0,DIVIDEND+3,SETLSB ;check for a carry from subtraction
;and add divisor to remainder if set
LDA REMAINDER+1 ;get remainder lsb
ADD 2,SP ;add divisor lsb to remainder lsb
STA REMAINDER+1 ;store remainder lsb
LDA REMAINDER ;get remainder msb
ADC 1,SP ;add divisor msb to remainder msb
STA REMAINDER ;store remainder msb
LDA DIVIDEND+3 ;get low byte of dividend
ADC #0 ;add carry to low bit of dividend
STA DIVIDEND+3 ;store low byte of dividend
BRA DECRMT ;do next shift and subtract
SETLSB BSET 0,DIVIDEND+3 ;set lsb of quotient to indicate
;successive subtraction
DECRMT DBNZ 3,SP,SHFTLP ;decrement loop counter and do next
;shift
*
* Move 32-bit dividend into INTACC1.....INTACC1+3 and put 16-bit
* remainder in INTACC2:INTACC2+1
*
LDA REMAINDER ;get remainder msb
STA 1,SP ;temporarily store remainder msb
LDA REMAINDER+1 ;get remainder lsb
STA 2,SP ;temporarily store remainder lsb
MOV DIVIDEND,QUOTIENT ;
MOV DIVIDEND+1,QUOTIENT+1 ;shift all four bytes of quotient
MOV DIVIDEND+2,QUOTIENT+2 ; 16 bits to the left
MOV DIVIDEND+3,QUOTIENT+3 ;
LDA 1,SP ;get final remainder msb
STA INTACC2 ;store final remainder msb
LDA 2,SP ;get final remainder lsb
STA INTACC2+1 ;store final remainder lsb
*
* Deallocate local storage, restore register values, and return from
* subroutine
*
AIS #3 ;deallocate temporary storage
PULX ;restore x-reg value
PULA ;restore accumulator value
PULH ;restore h-reg value
RTS ;return
********************************************************************************
********************************************************************************
*
* Table Lookup and Interpolation
*
* This subroutine performs table lookup and interpolation between two 16-bit
* dependent variables (Y) from a table of up to 256 enties (512 bytes) and
* allowing up to 256 interpolation levels between entries. INTACC1 contains
* the position of ENTRY2 and INTACC1+1 contains the interpolation fraction.
* The 16-bit result is placed in INTACC1+2=msb, INTACC1+3=lsb. INTACC2 is
* used to hold the two 16-bit entries during the routine.
*
* Y = ENTRY1 + (INTPFRC(ENTRY2 - ENTRY1))/256
*
TBLINT EQU *
*
ENTNUM EQU INTACC1 ;position of entry2 (0-255)
INTPFRC EQU INTACC1+1 ;interpolation fraction (1-255)/256
RESULT EQU INTACC1+2 ;16-bit interpolated Y value
ENTRY1 EQU INTACC2 ;16-bit enrty from table
ENTRY2 EQU INTACC2+2 ;16-bit entry from table
*
PSHH ;save h-register
PSHA ;save accumulator
PSHX ;save x-reg
AIS #-1 ;allocate one byte of temp storage
CLRH ;zero h-reg
CLRA ;zero accumulator
CLR 1,SP ;clear storage for difference sign
*
* Load H:X with position of ENTRY2
*
LDX ENTNUM ;get position of entry2 (0-255)
LSLX ;multiply by 2 (for 16-bit entries)
BCC GETENT ;if overflow from multiply occured,
;increment H-reg.
INCA ;accumulator = 1
PSHA ;push accumulator value on stack
PULH ;transfer acc. value to h register
*
* Get both entries from table, subtract ENTRY1 from ENTRY2 and store the
* 16-bit result.
*
GETENT LDA TABLE-2,x ;get entry1 lsb
STA ENTRY1
LDA TABLE-1,x ;get entry1 msb
STA ENTRY1+1
LDA TABLE,x ;get entry2 msb
STA ENTRY2
LDA TABLE+1,x ;get entry2 lsb
STA ENTRY2+1
SUB ENTRY1+1 ;entry2(lsb) - entry1(lsb)
STA RESULT+1 ;store result lsb
LDA ENTRY2
SBC ENTRY1 ;entry2(msb) - entry1(msb)
STA RESULT ;store result msb
*
*
* Two's complement 16-bit result if ENTRY1 was greater than ENTRY2, else
* go do multiply
*
*
TSTA ;test result msb for negative
BGE MLTFRAC ;go do multiply if postive
INC 1,SP ;set sign flag for negative result
NEG RESULT+1 ;two's complement result lsb
BCC NODECR ;check for borrow from zero
NEG RESULT ;two's complement result msb
DEC RESULT ;decrement result msb for borrow
BRA MLTFRAC ;go do multiply
NODECR NEG RESULT ;two's comp result msb (no borrow)
*
* (INTPFRC(RESULT:RESULT+1))/256 = Interpolated result
*
* Multiply result by interpolation fraction
*
MLTFRAC LDA INTPFRC ;get interpolation fraction
LDX RESULT+1 ;get result lsb
MUL ;multiply
STX RESULT+1 ;store upper 8-bits of result and throw
;away lower 8-bits (divide by 256)
LDA INTPFRC ;get interpolation fraction
LDX RESULT ;get result msb
MUL ;multiply
ADD RESULT+1 ;add result lsb to lower 8-bits of
;product
STA RESULT+1 ;store new result lsb
TXA ;get upper 8-bits of product
ADC #0 ;add carry from last addition
STA RESULT ;store result msb
*
* Y = ENTRY1 + Interpolated result
*
* Check sign flag to determine if interpolated result is to be added to
* or subtracted from ENTRY1
*
TST 1,SP ;test sign flag for negative
BLE ADDVAL ;if not set, add interpolated result
;to entry1, else subtract
LDA ENTRY1+1 ;get entry1 lsb
SUB RESULT+1 ;subtract result lsb
STA RESULT+1 ;store new result lsb
LDA ENTRY1 ;get entry1 msb
SBC RESULT ;subtact w/ carry result msb
STA RESULT ;store new result msb
BRA TBLDONE ;finished
ADDVAL LDA RESULT+1 ;get result lsb
ADD ENTRY1+1 ;add entry1 lsb
STA RESULT+1 ;store new result lsb
LDA ENTRY1 ;get entry1 msb
ADC RESULT ;add w/ carry result msb
STA RESULT ;store new result msb
*
* Deallocate local storage, restore register values, and return from
* subroutine.
*
TBLDONE AIS #1 ;deallocate local storage
PULX ;restore x-reg
PULA ;restore accumulator
PULH ;restore h-reg
RTS ;return from subroutine
*
* Sample of 16-bit table entries
*
TABLE EQU *
FDB !0000 ;entry 0
FDB !32767 ;entry 1
FDB !2416 ;entry 2
FDB !4271 ;entry 3
********************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -