Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Please check my arithmetic program

clranclran Member Posts: 20
Dear all,

I had wrote some program on multiplication and division. Please have a look whether there is any error in my program. Thanks!

It seem a bit unorganized in this message. If you are interested, i can forward to you in notepad format directly through your e-mail.

BWT 3BYTE $AA, $BB, $CC
$ZZ

ACC A - MSB
ACC B - LSB
ACCD - ACC A + ACC B


CALCULATE THE EXT BWT=ORG BWT(3 BYTE)*BWTEXT(1BYTE)
THEN ADD THE PRODUCT WITH $1F4(500)-DELTAETU
THEN PERFORM THIS MULTIPLICATION 260*CWT=$104(2 BYE)*CWT(3 BYTE)
THEN PERFORM THIS CALCULATION WWT= BWT+260*CWT IN ETU
THEN COVERT ETU TO SECOND 1ETU=7.75 MICRO SECOND -multiply the etu with 775 to get nano secong
THEN CONVERT NANO SECOND TO MILISECOND DIVEID BY 1000000
THEN FROM THE PERIOD IN MILI SECOND, NEED TO CALCULATE THE WAITING COUNTER SO CAN DELAY FOR
xx SECOND. 1COUNT=32.77MS(1 INTERRUPT)


BWT RMB 3 ; USE TO STORE CARD ATR BWT - 1474571ETU
CWT RMB 2 ; USE TO STORE CARD ATR CWT - 8203 ETU
MUL BWT RMB 4 ; USE TO STORE THE NEW BWT (ORG BWT*BWT EXT)
MUL CWT RMB 4 ; USE TO STORE THE MUL CWT (260*CWT)

WWT RMB 5 ; USE TO STORE THE WAITING TIME IN ETU (MUL BWT+MUL CWT)
ETUTONS RMB 7 ; USE TO STORE THE WAITING TIME IN NANO SECOND (WWT*7750NS)

TIMECNT RMB 1 ; 3 TIME TO DIVIDE BY 100 = 1000000
WWTCNT RMB 1 ; THE TIME OF REPETITION NEEDED TO COMPLETE THE DIVISION
WWTPTR RMB 1 ; POINTER TO THE BEGINNING OF WWT - DIVIDENT
QUOCNT RMB 1 ; THE NUMBER OF BYTE OF QUOTIENT FOR THE DIVISION
QUOTIENT RMB 7 ; USE TO STORE THE QUOTIENT
QUOTIENT ADD RMB 2 ; USE TO STORE THE QUOTIENT ADDRESS, SO THAT CAN SAVE QUOTIENT
; VALUE INTO NEXT BYTE OF QUOTIENT
REMAIN RMB 2 ; USE TO STORE THE REAMIN FROM EACH DIVISION
WWTINMS RMB 7 ; USE TO STORE WWT IN MILI SECOND THAT IS THE QUOTIENT FROM THE DIVISION

MSCNT RMB 1 ; TIME NEED TO DIVIDE WWTINMS TO GET THE TOF COUNTER
WAITING COUNTER RMB 2 ; USE TO STORE TOF COUNTER CALCULATED FROM WWTINMS/32MS
WAITING ADD RMB 2 ; USE TO STORE THE ADDRESS OF TOF COUNTER


PROGRAM FOR 3 BYTE (BWT) MULTIPLY WITH 1 BYTE (INF)

MUL EXT BWT LDX #MUL BWT
CLR 0,X
CLR 1,X
CLR 2,X
CLR 3,X
LDAA BWT+2
LDAB BWT EXT
MUL
STD 2,X

LDAA BWT+1
LDAB BWT EXT
MUL
ADDD 1,X
STD 1,X
BCC NEXT MUL
INC 0,X
NEXT MUL LDAA BWT
LDAB BWT EXT
MUL
ADDD 0,X
STD 0,X
RTS


BWT BWT+2 BWT+2
x EXT
0,X 1,X 2,X 3,X




Program to add BWT EXT with deltaETU=500etu/$1F4

ADD DELTA LDX #MUL BWT
LDD 2,X
ADDD #$1F4
STD 2,X
BCC NEXT ADD
INC 1,X
NEXT ADD RTS




PROGRAM FOR MULTIPLY 2 BYTE (CWT) WITH 2 BYTE ($104)

MUL CWT LDX #MUL CWT
CLR 0,X
CLR 1,X
CLR 2,X
CLR 3,X
LDAA CWT+1
LDAB #$04 ; 260 = $104
MUL
STD 2,X

LDAA CWT
LDAB #$04
MUL
ADDD 1,X
STD 1,X
BCC NEXT MUL
INC 0,X
NEXT MUL LDAA CWT+1
LDAB #$01
MUL
ADDD 1,X
STD 1,X
BCC NEXT MUL 1
INC 0,X
NEXT MUL 1 LDAA CWT
LDAB #$01
MUL
ADDD 0,X
STD 0,X
RTS


CWT CWT+1 - ATR CWT
x $01 $04 - 260
0,X 1,X 2,X 3,X - 260*CWT



CAL EXT WWT LDX #MUL BWT
LDY #MUL CWT
CLR WWT
CLR WWT+1
CLR WWT+2
CLR WWT+3
CLR WWT+4

LDD 2,X
ADDD 2,Y
STD WWT+3
BCC NEXT ADD
INC WWT+2
NEXT ADD LDD 0,X
ADDD 0,X
ADD WWT+1 ; TO ADD THE CARRY
STD WWT+1
BCC NEXT ADD 1
INC WWT
RTS

0,X 1,X 2,X 3,X - MUL BWT (EXT BWT)
+ 0,Y 1,Y 2,Y 3,Y - MUL CWT (260*CWT)
WWT WWT+1 WWT+2 WWT+3 WWT+4 - EXT WAITING TIME



CAL ORG WWT LDX #MUL CWT
CLR WWT
CLR WWT+1
CLR WWT+2
CLR WWT+3
CLR WWT+4

LDAA BWT
ADDA 3,X
STAA WWT+3
LDAA BWT+1
ADCA 2,X
STAA WWT+2
LDAA BWT+2
ADCA 1,X
STAA WWT+1
LDAA 0,X
ADCA #$00
STAA WWT

RTS

BWT+2 BWT+1 BWT ; ORG WWT(R) WILL ALWAYS BE ZERO. BUT IT FOR
+ 0,X 1,X 2,X 3,X ; THE CONVENIENT OF CONVERTING ETU TO SECOND
WWT WWT+1 WWT+2 WWT+3 WWT+4 ; 1474571+260*8203 = 3607371ETU (4 BYTE MAX)





COVERT ETU TO NANO SECOND (MULTIPLY 5 BYTEB MULTIPAND BYTE WITH 2 BYTE MULTIPLIER)

CONV TO NS LDX #ETUTONS ; 5 BYTE MULTIPAND WITH 2 BYTE MULTIPLER
CLR 0,X ; RESULT IN 7 BYTE PRODUCT
CLR 1,X
CLR 2,X
CLR 3,X
CLR 4,X
CLR 5,X
CLR 6,X

LDAA WWW+4
LDAB #50 ; 7.75MICRO SECOND = 7750NANO SECOND
MUL
STD 5,X

LDAA WWT+3
LDAB #50
MUL
ADDD 4,X
STD 4,X
BCC NEXT CONV
INC 3,X
NEXT COV LDAA WWT+2
LDAB #50
MUL
ADDD 3,X
STD 3,X
BCC NEXT CONV 1
INC 2,X
NEXT COV 1 LDAA WWT+1
LDAB #50
MUL
ADDD 2,X
STD 2,X
BCC NEXT CONV 2
INC 1,X
NEXT CONV 2 LDAA WWT
LDAB #50
MUL
ADDD 1,X
STD 1,X ; WILL NOT HAVE CARRY SINCE MULTIPLY WITH MSB OF MULTIPAND


LDAA WWT+4
LDAB #75
MUL
ADDD 4,X
STD 4,X
BCC NEXT CONV 3
INC 3,X
BNE NEXT CONV 3
INC 2,X
NEXT CONV 3 LDAA WWT+3
LDAB #75
MUL
ADDD 3,X
STD 3,X
BCC NEXT CONV 4
INC 2,X
BNE NEXT CONV 4
INC 1,X
NEXT CONV 4 LDAA WWT+2
LDAB #75
MUL
ADDD 2,X
STD 2,X
BCC NEXT CONV 5
INC 1,X
BNE NEXT CONV 5
INC 0,X
NEXT CONV 5 LDAA WWT+1
LDAB #75
MUL
ADDD 1,X
STD 1,X
BCC NEXT CONV 6
INC 0,X
NEXT CONV 6 LDAA WWT
LDAB #75
MUL
ADDD 0,X
STD 0,X
RTS


WWT WWT+1 WWT+2 WWT+3 WWT+4 - WAITING TIME IN ETU
X 75 50 - 7550NS
0,X 1,X 2,X 3,X 4,X 5,X 6,X - WAITING TIME IN NANO SECOND



CONVERT NANO SECOND TO MILI SECOND (DEVIDE 100 3 TIMES = DEVIDE 1000000/ devide 7 byte with 1 byte)

CONV TO MS LDD #QUOTIENT
STD QUOTIENT ADD
LDY #ETUTOS ; GET SATARTING ADD OF WWT
LDAA #3 ; DEVIDE WWT WITH 100 3 TIMES
STAA TIMECNT
LDAB #7 ; THE MAX DIVIDENT-FROM PREVIOUS CALCULATION

CHECK NEXT WWT LDAA 0,Y ; CHECK ANY BYTE IS ZERO BEFORE DEVIDE THEM
CMPA #$00 ; START WITH FIRST BYTE THAT IS NOT ZERO
BNE DIV100
INY
DECB
BNE CHECK NEXT WWT
BRA RESULT 0 ; IF ALL DEVIDENT IS ZERO, THEN THE RESULT
; IS 0

DIV 100 DECB ; SINCE 5 BYTE DIVIDENT ONLY NEED TO DEVIDE
; (NO OF BYTE -1) TIMES. DIVIDE 2 BYTE AT
; A TIME USING ACC D
STAB WWTCNT ; TIME IDIV REQUIRED IN ORDER TO DIVIDE ALL
; THE BYTE IN WWT
STY WWTPTR ; THE NON-ZERO MSB OF THE ETUTONS
AGN DIV 100 LDY WWTPTR
LDAA 0,Y ; TO CHECK WHETHER MSB>100
CMPA #100
BLO ADJUST QUO
STAB QUOCNT ; IF MSB>100, THEN QUOCNT=WWTCNT
BRA NEXT WWT
ADJUST QUO DECB ; IF MSB<100, THEN QUOCNT=WWTCNT-1
STAB QUOCNT ; QUOCNT INDICATE THE NUMBER OF BYTE FOR QUOTIENT
; FOR THAT DIVISION

NEXT WWT LDD 0,Y ; CHECK WHETHER DIVIDENT>DIVISOR
CMP #100 ; NOT APPLICABLE FOR FIRST TIME
BLO QUO ZERO ; THIS IS TO AVOID 2 BYTE DEVIDENT < DIVISOR
LDX INT100 ; SINCE IF 2 BYTE DIVIDENT < DIVISOR, THE
IDIV ; QUOTIENT BYTE SHOULD EB ZERO AND MOVE WITH
STD REMAIN ; NEXT BYTE DIVIDENT
XGDX ; THE QUOTIENT IS IN ACC D

STORE QA CMPA #$00 ; STORE QUOTIENT ONLY IF NOT ZERO
BEQ STORE QB ; 1ST BYTE QUOTIENT IS ZERO SO STORE 2ND BYTE QUOTIENT
LDX QUOTIENT ADD ; GET THE QUOTIENT ADDRESS
STAA 0,X ; STORE THE QUOTIENT VALUE INTO QUOTIENT ADDRESS
INX ; INCREMENT QUOTIENT ADDRESS SO NEXT QUOTIENT WILL
STX QUOTIENT ADD ; BE STORED AT NEXT QUOTIENT BYTE

STORE QB LDX QUOTIENT ADD
STAB 0,X
INX
STX QUOTIENT ADD

LDD 0,Y ;
SUBD REMAIN
STAB 1,Y
INY ; INCREMENT Y TO GET THE NEXT BYTE OF WWT
DEC WWTCNT ; DECREMENT THE TIME THE WWT NEED TO DIVIDE
BNE NEXT WWT ; DIVIDE NEXT 2 BYTE OF WWT
BRA JUMP

QUO ZERO LDAA #$00 ; STORE $00 INTO QUOTIENT SINCE THE 2 BYTE
LDX QUOTIENT ADD ; DIVIDENT IS SMALLER THAN DIVISOR
STAA 0,X
INX ; INCREMENT QUOTIENT ADDRESS TO POINT TO NEXT BYTE
STX QUOTIENT ADD

INY ; INCREMENT Y TO GET THE NEXT BYTE OF WWT
DEC WWTCNT ; DECREMENT THE TIME THE WWT NEED TO DIVIDE
BNE NEXT WWT ; DIVIDE NEXT 2 BYTE OF WWT

JUMP LDAA QUOCNT ; THE CURRENT QUOTIENT COUNT WILL BECOME
DECA ; SINCE N BYTE VALU ONLY NEED TO DEVIDE (N-1) TIMES
STAA WWTCNT ; NEXT CALCULATION WWT COUNT
LDD #WWTINMS ; GET WWT IN WWTINMS TABLE FOR NEXT CAL
; SINCE QUOTIENT WILL BE STORED THERE AFTER 1ST
; TIME THE WWT DIVIDE BY 100
STD WWTPTR
LDD #QUOTIENT ; TO REINITIALIZE THE QUO ADD TO THE BEGINNING
STD QUOTIENT ADD
LDX #QUOTINET ; LOAD X WITH SOURCE ADD
LDY #WWTINMS ; LOAY Y WITH DESTINATION ADD
NEXT QUO LDAA 0,X ; TRANSFER QOUTIENT DATA TO WWTINMS TABLE
STAA 0,Y
INX
INY
DEC QUOCNT
BNE NEXT QUO

DEC TIMECNT ; CHECK WHETHER STILL NEED TO DEVIDE BY INT100
BNE AGN DIV 100
RTS


CONVERT MILI SECOND INTO COUNTER FOR OVERFLOW INTERRUPT (devide 7 bye with 1 byte)
(actually maximum 2/3 byte devide by 1 byte - result 2 byte only)


CAL TOF CNT LDD #WAITING COUNTER; STORE TOF COUNTER ADDRESS TO TOF ADD SO THAT CAN
STD WAITING ADD ; STORE COUNTER TO NEXT BYTE OF ADDRESS
LDAA WWTCNT ; THIS VALUE IS TIME TO DEVIDE WHICH ALREADY DECREMENT
; BY PREVIOUS SUBROUTINE
STAA MSCNT ; INDICATE HOW MANY TIME NEED TO DIVIDE THE WWTINMS
; TO GET THE TOF COUNTER
LDY #WWTINMS ; EVERY BYTE OF DATA WILL HAVE VALUE
; DO NOT HAVE TO CHECK FOR ZERO (DONE BY PREVIOUS SUBROUTINE)
NEXT MS LDD 0,Y
CMP #32
BLO QUO ZERO
LDX #32 ; SINCE INTERRUPT OCCUR EVERY 23 MS
IDIV
STD REMAIN
XGDX


STORE QA CMPA #$00
BEQ STORE QB
LDX WAITING ADD
STAA 0,X
INX
STX WAITING ADD

STORE QB LDX WAITING ADD
STAB 0,X
INX
STX WAITING ADD
LDD 0.Y
SUBD REMAIN
STAB 1,Y
INY
DEC MSCNT
BNE NEXT MS
INC 0,X ; THE CARRY FORWARD THE COUNTER
; IE 234.67=235/234=235
; TO MAKE SURE ALL THE RESPONSE IS RECEIVED
RTS

QUO ZERO LDD #$00
BRA STORE QA




Comments

  • anthrax11anthrax11 Member Posts: 511
    : Dear all,
    :
    : I had wrote some program on multiplication and division. Please have a look whether there is any error in my program. Thanks!
    :
    : It seem a bit unorganized in this message. If you are interested, i can forward to you in notepad format directly through your e-mail.
    :
    [code]
    : BWT 3BYTE $AA, $BB, $CC
    : $ZZ
    :
    : ACC A - MSB
    : ACC B - LSB
    : ACCD - ACC A + ACC B
    :
    :
    : CALCULATE THE EXT BWT=ORG BWT(3 BYTE)*BWTEXT(1BYTE)
    : THEN ADD THE PRODUCT WITH $1F4(500)-DELTAETU
    : THEN PERFORM THIS MULTIPLICATION 260*CWT=$104(2 BYE)*CWT(3 BYTE)
    : THEN PERFORM THIS CALCULATION WWT= BWT+260*CWT IN ETU
    : THEN COVERT ETU TO SECOND 1ETU=7.75 MICRO SECOND -multiply the etu with 775 to get nano secong
    : THEN CONVERT NANO SECOND TO MILISECOND DIVEID BY 1000000
    : THEN FROM THE PERIOD IN MILI SECOND, NEED TO CALCULATE THE WAITING COUNTER SO CAN DELAY FOR
    : xx SECOND. 1COUNT=32.77MS(1 INTERRUPT)
    :
    :
    : BWT RMB 3 ; USE TO STORE CARD ATR BWT - 1474571ETU
    : CWT RMB 2 ; USE TO STORE CARD ATR CWT - 8203 ETU
    : MUL BWT RMB 4 ; USE TO STORE THE NEW BWT (ORG BWT*BWT EXT)
    : MUL CWT RMB 4 ; USE TO STORE THE MUL CWT (260*CWT)
    :
    : WWT RMB 5 ; USE TO STORE THE WAITING TIME IN ETU (MUL BWT+MUL CWT)
    : ETUTONS RMB 7 ; USE TO STORE THE WAITING TIME IN NANO SECOND (WWT*7750NS)
    :
    : TIMECNT RMB 1 ; 3 TIME TO DIVIDE BY 100 = 1000000
    : WWTCNT RMB 1 ; THE TIME OF REPETITION NEEDED TO COMPLETE THE DIVISION
    : WWTPTR RMB 1 ; POINTER TO THE BEGINNING OF WWT - DIVIDENT
    : QUOCNT RMB 1 ; THE NUMBER OF BYTE OF QUOTIENT FOR THE DIVISION
    : QUOTIENT RMB 7 ; USE TO STORE THE QUOTIENT
    : QUOTIENT ADD RMB 2 ; USE TO STORE THE QUOTIENT ADDRESS, SO THAT CAN SAVE QUOTIENT
    : ; VALUE INTO NEXT BYTE OF QUOTIENT
    : REMAIN RMB 2 ; USE TO STORE THE REAMIN FROM EACH DIVISION
    : WWTINMS RMB 7 ; USE TO STORE WWT IN MILI SECOND THAT IS THE QUOTIENT FROM THE DIVISION
    :
    : MSCNT RMB 1 ; TIME NEED TO DIVIDE WWTINMS TO GET THE TOF COUNTER
    : WAITING COUNTER RMB 2 ; USE TO STORE TOF COUNTER CALCULATED FROM WWTINMS/32MS
    : WAITING ADD RMB 2 ; USE TO STORE THE ADDRESS OF TOF COUNTER
    :
    :
    : PROGRAM FOR 3 BYTE (BWT) MULTIPLY WITH 1 BYTE (INF)
    :
    : MUL EXT BWT LDX #MUL BWT
    : CLR 0,X
    : CLR 1,X
    : CLR 2,X
    : CLR 3,X
    : LDAA BWT+2
    : LDAB BWT EXT
    : MUL
    : STD 2,X
    :
    : LDAA BWT+1
    : LDAB BWT EXT
    : MUL
    : ADDD 1,X
    : STD 1,X
    : BCC NEXT MUL
    : INC 0,X
    : NEXT MUL LDAA BWT
    : LDAB BWT EXT
    : MUL
    : ADDD 0,X
    : STD 0,X
    : RTS
    :
    :
    : BWT BWT+2 BWT+2
    : x EXT
    : 0,X 1,X 2,X 3,X
    :
    :
    :
    :
    : Program to add BWT EXT with deltaETU=500etu/$1F4
    :
    : ADD DELTA LDX #MUL BWT
    : LDD 2,X
    : ADDD #$1F4
    : STD 2,X
    : BCC NEXT ADD
    : INC 1,X
    : NEXT ADD RTS
    :
    :
    :
    :
    : PROGRAM FOR MULTIPLY 2 BYTE (CWT) WITH 2 BYTE ($104)
    :
    : MUL CWT LDX #MUL CWT
    : CLR 0,X
    : CLR 1,X
    : CLR 2,X
    : CLR 3,X
    : LDAA CWT+1
    : LDAB #$04 ; 260 = $104
    : MUL
    : STD 2,X
    :
    : LDAA CWT
    : LDAB #$04
    : MUL
    : ADDD 1,X
    : STD 1,X
    : BCC NEXT MUL
    : INC 0,X
    : NEXT MUL LDAA CWT+1
    : LDAB #$01
    : MUL
    : ADDD 1,X
    : STD 1,X
    : BCC NEXT MUL 1
    : INC 0,X
    : NEXT MUL 1 LDAA CWT
    : LDAB #$01
    : MUL
    : ADDD 0,X
    : STD 0,X
    : RTS
    :
    :
    : CWT CWT+1 - ATR CWT
    : x $01 $04 - 260
    : 0,X 1,X 2,X 3,X - 260*CWT
    :
    :
    :
    : CAL EXT WWT LDX #MUL BWT
    : LDY #MUL CWT
    : CLR WWT
    : CLR WWT+1
    : CLR WWT+2
    : CLR WWT+3
    : CLR WWT+4
    :
    : LDD 2,X
    : ADDD 2,Y
    : STD WWT+3
    : BCC NEXT ADD
    : INC WWT+2
    : NEXT ADD LDD 0,X
    : ADDD 0,X
    : ADD WWT+1 ; TO ADD THE CARRY
    : STD WWT+1
    : BCC NEXT ADD 1
    : INC WWT
    : RTS
    :
    : 0,X 1,X 2,X 3,X - MUL BWT (EXT BWT)
    : + 0,Y 1,Y 2,Y 3,Y - MUL CWT (260*CWT)
    : WWT WWT+1 WWT+2 WWT+3 WWT+4 - EXT WAITING TIME
    :
    :
    :
    : CAL ORG WWT LDX #MUL CWT
    : CLR WWT
    : CLR WWT+1
    : CLR WWT+2
    : CLR WWT+3
    : CLR WWT+4
    :
    : LDAA BWT
    : ADDA 3,X
    : STAA WWT+3
    : LDAA BWT+1
    : ADCA 2,X
    : STAA WWT+2
    : LDAA BWT+2
    : ADCA 1,X
    : STAA WWT+1
    : LDAA 0,X
    : ADCA #$00
    : STAA WWT
    :
    : RTS
    :
    : BWT+2 BWT+1 BWT ; ORG WWT(R) WILL ALWAYS BE ZERO. BUT IT FOR
    : + 0,X 1,X 2,X 3,X ; THE CONVENIENT OF CONVERTING ETU TO SECOND
    : WWT WWT+1 WWT+2 WWT+3 WWT+4 ; 1474571+260*8203 = 3607371ETU (4 BYTE MAX)
    :
    :
    :
    :
    :
    : COVERT ETU TO NANO SECOND (MULTIPLY 5 BYTEB MULTIPAND BYTE WITH 2 BYTE MULTIPLIER)
    :
    : CONV TO NS LDX #ETUTONS ; 5 BYTE MULTIPAND WITH 2 BYTE MULTIPLER
    : CLR 0,X ; RESULT IN 7 BYTE PRODUCT
    : CLR 1,X
    : CLR 2,X
    : CLR 3,X
    : CLR 4,X
    : CLR 5,X
    : CLR 6,X
    :
    : LDAA WWW+4
    : LDAB #50 ; 7.75MICRO SECOND = 7750NANO SECOND
    : MUL
    : STD 5,X
    :
    : LDAA WWT+3
    : LDAB #50
    : MUL
    : ADDD 4,X
    : STD 4,X
    : BCC NEXT CONV
    : INC 3,X
    : NEXT COV LDAA WWT+2
    : LDAB #50
    : MUL
    : ADDD 3,X
    : STD 3,X
    : BCC NEXT CONV 1
    : INC 2,X
    : NEXT COV 1 LDAA WWT+1
    : LDAB #50
    : MUL
    : ADDD 2,X
    : STD 2,X
    : BCC NEXT CONV 2
    : INC 1,X
    : NEXT CONV 2 LDAA WWT
    : LDAB #50
    : MUL
    : ADDD 1,X
    : STD 1,X ; WILL NOT HAVE CARRY SINCE MULTIPLY WITH MSB OF MULTIPAND
    :
    :
    : LDAA WWT+4
    : LDAB #75
    : MUL
    : ADDD 4,X
    : STD 4,X
    : BCC NEXT CONV 3
    : INC 3,X
    : BNE NEXT CONV 3
    : INC 2,X
    : NEXT CONV 3 LDAA WWT+3
    : LDAB #75
    : MUL
    : ADDD 3,X
    : STD 3,X
    : BCC NEXT CONV 4
    : INC 2,X
    : BNE NEXT CONV 4
    : INC 1,X
    : NEXT CONV 4 LDAA WWT+2
    : LDAB #75
    : MUL
    : ADDD 2,X
    : STD 2,X
    : BCC NEXT CONV 5
    : INC 1,X
    : BNE NEXT CONV 5
    : INC 0,X
    : NEXT CONV 5 LDAA WWT+1
    : LDAB #75
    : MUL
    : ADDD 1,X
    : STD 1,X
    : BCC NEXT CONV 6
    : INC 0,X
    : NEXT CONV 6 LDAA WWT
    : LDAB #75
    : MUL
    : ADDD 0,X
    : STD 0,X
    : RTS
    :
    :
    : WWT WWT+1 WWT+2 WWT+3 WWT+4 - WAITING TIME IN ETU
    : X 75 50 - 7550NS
    : 0,X 1,X 2,X 3,X 4,X 5,X 6,X - WAITING TIME IN NANO SECOND
    :
    :
    :
    : CONVERT NANO SECOND TO MILI SECOND (DEVIDE 100 3 TIMES = DEVIDE 1000000/ devide 7 byte with 1 byte)
    :
    : CONV TO MS LDD #QUOTIENT
    : STD QUOTIENT ADD
    : LDY #ETUTOS ; GET SATARTING ADD OF WWT
    : LDAA #3 ; DEVIDE WWT WITH 100 3 TIMES
    : STAA TIMECNT
    : LDAB #7 ; THE MAX DIVIDENT-FROM PREVIOUS CALCULATION
    :
    : CHECK NEXT WWT LDAA 0,Y ; CHECK ANY BYTE IS ZERO BEFORE DEVIDE THEM
    : CMPA #$00 ; START WITH FIRST BYTE THAT IS NOT ZERO
    : BNE DIV100
    : INY
    : DECB
    : BNE CHECK NEXT WWT
    : BRA RESULT 0 ; IF ALL DEVIDENT IS ZERO, THEN THE RESULT
    : ; IS 0
    :
    : DIV 100 DECB ; SINCE 5 BYTE DIVIDENT ONLY NEED TO DEVIDE
    : ; (NO OF BYTE -1) TIMES. DIVIDE 2 BYTE AT
    : ; A TIME USING ACC D
    : STAB WWTCNT ; TIME IDIV REQUIRED IN ORDER TO DIVIDE ALL
    : ; THE BYTE IN WWT
    : STY WWTPTR ; THE NON-ZERO MSB OF THE ETUTONS
    : AGN DIV 100 LDY WWTPTR
    : LDAA 0,Y ; TO CHECK WHETHER MSB>100
    : CMPA #100
    : BLO ADJUST QUO
    : STAB QUOCNT ; IF MSB>100, THEN QUOCNT=WWTCNT
    : BRA NEXT WWT
    : ADJUST QUO DECB ; IF MSB<100, THEN QUOCNT=WWTCNT-1
    : STAB QUOCNT ; QUOCNT INDICATE THE NUMBER OF BYTE FOR QUOTIENT
    : ; FOR THAT DIVISION
    :
    : NEXT WWT LDD 0,Y ; CHECK WHETHER DIVIDENT>DIVISOR
    : CMP #100 ; NOT APPLICABLE FOR FIRST TIME
    : BLO QUO ZERO ; THIS IS TO AVOID 2 BYTE DEVIDENT < DIVISOR
    : LDX INT100 ; SINCE IF 2 BYTE DIVIDENT < DIVISOR, THE
    : IDIV ; QUOTIENT BYTE SHOULD EB ZERO AND MOVE WITH
    : STD REMAIN ; NEXT BYTE DIVIDENT
    : XGDX ; THE QUOTIENT IS IN ACC D
    :
    : STORE QA CMPA #$00 ; STORE QUOTIENT ONLY IF NOT ZERO
    : BEQ STORE QB ; 1ST BYTE QUOTIENT IS ZERO SO STORE 2ND BYTE QUOTIENT
    : LDX QUOTIENT ADD ; GET THE QUOTIENT ADDRESS
    : STAA 0,X ; STORE THE QUOTIENT VALUE INTO QUOTIENT ADDRESS
    : INX ; INCREMENT QUOTIENT ADDRESS SO NEXT QUOTIENT WILL
    : STX QUOTIENT ADD ; BE STORED AT NEXT QUOTIENT BYTE
    :
    : STORE QB LDX QUOTIENT ADD
    : STAB 0,X
    : INX
    : STX QUOTIENT ADD
    :
    : LDD 0,Y ;
    : SUBD REMAIN
    : STAB 1,Y
    : INY ; INCREMENT Y TO GET THE NEXT BYTE OF WWT
    : DEC WWTCNT ; DECREMENT THE TIME THE WWT NEED TO DIVIDE
    : BNE NEXT WWT ; DIVIDE NEXT 2 BYTE OF WWT
    : BRA JUMP
    :
    : QUO ZERO LDAA #$00 ; STORE $00 INTO QUOTIENT SINCE THE 2 BYTE
    : LDX QUOTIENT ADD ; DIVIDENT IS SMALLER THAN DIVISOR
    : STAA 0,X
    : INX ; INCREMENT QUOTIENT ADDRESS TO POINT TO NEXT BYTE
    : STX QUOTIENT ADD
    :
    : INY ; INCREMENT Y TO GET THE NEXT BYTE OF WWT
    : DEC WWTCNT ; DECREMENT THE TIME THE WWT NEED TO DIVIDE
    : BNE NEXT WWT ; DIVIDE NEXT 2 BYTE OF WWT
    :
    : JUMP LDAA QUOCNT ; THE CURRENT QUOTIENT COUNT WILL BECOME
    : DECA ; SINCE N BYTE VALU ONLY NEED TO DEVIDE (N-1) TIMES
    : STAA WWTCNT ; NEXT CALCULATION WWT COUNT
    : LDD #WWTINMS ; GET WWT IN WWTINMS TABLE FOR NEXT CAL
    : ; SINCE QUOTIENT WILL BE STORED THERE AFTER 1ST
    : ; TIME THE WWT DIVIDE BY 100
    : STD WWTPTR
    : LDD #QUOTIENT ; TO REINITIALIZE THE QUO ADD TO THE BEGINNING
    : STD QUOTIENT ADD
    : LDX #QUOTINET ; LOAD X WITH SOURCE ADD
    : LDY #WWTINMS ; LOAY Y WITH DESTINATION ADD
    : NEXT QUO LDAA 0,X ; TRANSFER QOUTIENT DATA TO WWTINMS TABLE
    : STAA 0,Y
    : INX
    : INY
    : DEC QUOCNT
    : BNE NEXT QUO
    :
    : DEC TIMECNT ; CHECK WHETHER STILL NEED TO DEVIDE BY INT100
    : BNE AGN DIV 100
    : RTS
    :
    :
    : CONVERT MILI SECOND INTO COUNTER FOR OVERFLOW INTERRUPT (devide 7 bye with 1 byte)
    : (actually maximum 2/3 byte devide by 1 byte - result 2 byte only)
    :
    :
    : CAL TOF CNT LDD #WAITING COUNTER; STORE TOF COUNTER ADDRESS TO TOF ADD SO THAT CAN
    : STD WAITING ADD ; STORE COUNTER TO NEXT BYTE OF ADDRESS
    : LDAA WWTCNT ; THIS VALUE IS TIME TO DEVIDE WHICH ALREADY DECREMENT
    : ; BY PREVIOUS SUBROUTINE
    : STAA MSCNT ; INDICATE HOW MANY TIME NEED TO DIVIDE THE WWTINMS
    : ; TO GET THE TOF COUNTER
    : LDY #WWTINMS ; EVERY BYTE OF DATA WILL HAVE VALUE
    : ; DO NOT HAVE TO CHECK FOR ZERO (DONE BY PREVIOUS SUBROUTINE)
    : NEXT MS LDD 0,Y
    : CMP #32
    : BLO QUO ZERO
    : LDX #32 ; SINCE INTERRUPT OCCUR EVERY 23 MS
    : IDIV
    : STD REMAIN
    : XGDX
    :
    :
    : STORE QA CMPA #$00
    : BEQ STORE QB
    : LDX WAITING ADD
    : STAA 0,X
    : INX
    : STX WAITING ADD
    :
    : STORE QB LDX WAITING ADD
    : STAB 0,X
    : INX
    : STX WAITING ADD
    : LDD 0.Y
    : SUBD REMAIN
    : STAB 1,Y
    : INY
    : DEC MSCNT
    : BNE NEXT MS
    : INC 0,X ; THE CARRY FORWARD THE COUNTER
    : ; IE 234.67=235/234=235
    : ; TO MAKE SURE ALL THE RESPONSE IS RECEIVED
    : RTS
    :
    : QUO ZERO LDD #$00
    : BRA STORE QA
    :
    :
    :
    [/code]


    [green]Sorry, I don`t know this type of asm language, but if you want to keep the formatting of the code, use code tags:[/green]
    [b][leftbr]code[rightbr][/b]
    ; code here
    [b][leftbr]/code[rightbr][/b]

Sign In or Register to comment.