Skip to content

Instantly share code, notes, and snippets.

@krishnakumarcn
Last active December 1, 2016 11:51
Show Gist options
  • Save krishnakumarcn/52ab92add98a075999e2a735f25a86f4 to your computer and use it in GitHub Desktop.
Save krishnakumarcn/52ab92add98a075999e2a735f25a86f4 to your computer and use it in GitHub Desktop.
CHI
;Matrix Multiplication
MOV DPTR,#0000H
MOVX A,@DPTR
MOV R7,A
PUSH A
INC DPTR
MOVX A,@DPTR
MOV R6,A
PUSH A
INC DPTR
MOVX A,@DPTR
MOV R5,A
INC DPTR
MOVX A,@DPTR
MOV R4,A
MOV A,R6
XRL A,R5
JNZ EL
MOV A,R4
MOV R5,A
PUSH A
;NOW ORDERS IN R7,R6 AND R5
MOV DPTR,#0030H
MOV A,R7
MOVX @DPTR,A
MOV A,R5
INC DPTR
MOVX @DPTR,A ;RESULT ORDER AT #0030H
;----------------------------------------------;
TRANSPOSE:
MOV DPTR,#0040H
MOV R3,#0020H
MOV A,R5
MOV R1,A
OUTER:
MOV A,R6
MOV R2,A
MOV A,R3
MOV R0,A
INNER: MOVX A,@R0
MOVX @DPTR,A
INC DPTR
MOV A,R0
ADD A,R5
MOV R0,A
DJNZ R2,INNER
INC R3
DJNZ R1,OUTER
;--------RESTORE ORDERS-----------;
POP A
MOV R5,A
POP A
MOV R6,A
POP A
MOV R7,A
;----------MULTIPLICATION------------;
MOV P0,#10H
MOV DPTR,#50H
MOV A,R7
MOV R4,A
THIRD:
MOV R1,#40H
MOV A,R7
MOV R3,A
OUTR: MOV R0,P0
MOV A,R6
MOV R2,A
MOV R5,#0
INN: MOVX A,@R0
MOV B,A
MOVX A,@R1
MUL AB
ADD A,R5
MOV R5,A
INC R0
INC R1
DJNZ R2,INN
MOV A,R5
MOVX @DPTR,A
INC DPTR
DJNZ R3,OUTR
MOV A,P0
ADD A,R6
MOV P0,A
DJNZ R4,THIRD
EL: SJMP EL
;fib with prime
;------find fibnocci----------;
mov dptr,#000h
movx a,@dptr
mov r7,a
mov dptr,#0010h
mov r6,#0h
mov r5,#1h
mov r0,#0020h
here: mov a,r6
movx @dptr,a
call prime
add a,r5
mov r6,a
mov a,r6
subb a,r5
mov r5,a
inc dptr
djnz r7,here
;--------fibnocci@ 0010h onwards------;
el: sjmp el
prime:
push a
mov r4,a
cjne a,#0,next
sjmp notprime
next: cjne a,#1,next2
sjmp notprime
next2:
mov r3,#2h
again: mov b,r3
div ab
mov a,b
jz notprime
inc r3
mov a,r4
subb a,r3
jz isprime
sjmp again
isprime:mov a,r4
movx @r0,a
inc r0
notprime:
pop a
ret
;TRANSPOSE
MOV DPTR,#0000H
MOVX A,@DPTR
MOV R2,A ;R2 - m
MOV DPTR,#0021H
MOVX @DPTR,A
MOV DPTR,#0001H
MOVX A,@DPTR
MOV R3,A ;R3 - n
MOV DPTR,#0020H
MOVX @DPTR,A
MOV DPTR,#0010H ;ORIGINAL POINTER
MOV R0,#0030H ;TO WRITE
MOV A,R3
MOV R6,A
OUTER: MOV A,DPL
MOV R5,A
MOV A,R2
MOV R4,A
INNER:
MOVX A,@DPTR
MOVX @R0,A
MOV A,DPL
ADD A,R3
MOV DPL,A
INC R0
DJNZ R4,INNER
MOV A,R5
MOV DPL,A
INC DPTR
DJNZ R6,OUTER
EL: SJMP EL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment