Logo Foltyn Presentation
Table of Contents Previous Page Next Page
Content-Symbol-Img


Programming Kit COP-8 Logo

Page  1 2 3 4

COP-8
Programming Kit


Programming Examples in COP8-Assembler

;---------------- 2-Byte Binary Division ---------------
;Dividend in [3,2] Divisor in [1,0] Quotient in [3,2] Remainder in [5,4]
DIV:LDQUOTIENTLO,#X'FF;Division by zero
LDQUOTIENTHI,#X'FF
LDB,#0
LDA,[B+]
ORA,[B]
IFEQA,#0a
JMPFINISH
LDQUOTIENTLO,#X'00
LDQUOTIENTHI,#X'00
LDTEMPCNT,#16;Repeat for all bits
LDB,#5
LD[B-],#0
LD[B],#0
LDX,#4
LSHIFT:RC;Shift left Dividend, Quotient and Remainder
LDB,#2
LOOP:LDA,[B]
ADCA,[B]
XA,[B+]
IFBNE#6
JPLOOP
TSUBT:SC;Test if substractable
LDB,#0
LDA,[X+]
SUBCA,[B]
LDB,#1
LDA,[X-]
SUBCA,[B]
IFNC
JPTEST
SUBT:LDB,#0;Substract
LDA,[X]
SUBCA,[B]
XA,[X+]
LDB,#1
LDA,[X]
SUBCA,[B]
XA,[X-]
LDB,#2
SBIT0,[B]
TEST:DRSZTEMPCNT
JMPLSHIFT
FINISH:........

;---------------- Binary Square-Root ---------------
;------------------ Inputvalues in XXXX ----------------
SQUAREROOT:LDB,#MULTKANDLO;MULTKAND = SQUAREROOT (Result)
LD[B+],#0
LDIILO,#0;II = Hikingbitword
LDIIHI,#080
LDTEMPCNT,#010
FORMTESTWORD:LDB,#MULTKANDLO
LDA,[B]
ORA,IILO
XA,[B+]
LDA,[B]
ORA,IIHI
XA,[B+]
JSRSQUARE
COMPARE:LDX,#XXXX
LDB,#MULTKATORLO
LDTEMPCNT1,#4
SBIT0,FLAGS
SC
COMP2:LDA,[X+]
SUBCA,[B]
XA,[B];for purpose of INC B only
XA,[B+]
IFEQA,#0
JPCOMP3
RBIT0,FLAGS
COMP3:DRSZTEMPCNT1
JPCOMP2
EVALUE:IFBIT0,FLAGS
JPEND
IFC
JPSHIFTRIGHTII
RESETTESTBIT:LDX,#IILO
LDB,#MULTKANDLO
LDTEMPCNT1,#2
RES:LDA,[X+]
XORA,#0FF
ANDA,[B]
XA,[B+]
DRSZTEMPCNT1
JPRES
SHIFTRIGHTII:LDB,#IIHI
RC
LDTEMPCNT1,#2
SHIFT:LDA,[B]
RRCA
XA,[B-]
DRSZTEMPCNT1
JPSHIFT
DRSZTEMPCNT
JMPFORMTESTWORD
FINISH2:.......;Result in MULTKAND