Convolution.asm
aaronjohnsabu1999_IITB-EE-Sem05/EE337/Labwork/Q2/Reading_Material/Codes/Convolution.asm
org  0000h
ljmp main
org  0200h

init_1:							;Reserves 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x50, 0x51, 0x52
		mov 0x50, #0x40		;0x50	-	location of x1
		mov 0x51, #0x45		;0x51	-	location of y1
		mov 0x52, #0x60		;0x52	-	location of storage
		mov 0x40, #0x0A
		mov 0x41, #0x52
		mov 0x42, #0xC6
		mov 0x45, #0xF9
		mov 0x46, #0x08
		mov 0x47, #0xD7
ret

init_2:							;Reserves 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29
		mov 0x20, #0x00		;0x20	-	0x00
		mov 0x21, #0x00		;0x21	-	0x00
		mov  R0,   0x51
		mov  A,   @R0
		mov  0x22, A		;0x22	-	y1
		inc  R0
		mov  A,   @R0
		mov  0x23, A		;0x23	-	y2
		inc  R0
		mov  A,   @R0
		mov  0x24, A		;0x24	-	y3
		mov 0x25, #0x00		;0x25	-	0x00
		mov 0x26, #0x00		;0x26	-	0x00
		
		mov  R0,   0x50
		mov  0x29, @R0		;0x2C	-	x1
		inc  R0
		mov  0x28, @R0		;0x2B	-	x2
		inc  R0
		mov  0x27, @R0		;0x2A	-	x3
ret

adder_16bit:					;Reserves 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
		mov  A,    0x31		;0x31	-	LSB1
		add  A,    0x33		;0x33	-	LSB2
		mov  0x36, A		;0x36	-	LSBY
		mov  A,    0x30		;0x30	-	MSB1
		addc A,    0x32		;0x32	-	MSB2
		mov  0x35, A		;0x35	-	MSBY
		mov  A,   #0x00
		addc A,   #0x00
		mov  0x34, A		;0x34	-	C
ret

convolution:
		mov  R2,  #0xFF
		
CP0:	inc  R2
		mov  R5,  #0x00
		mov  R4,  #0x00
		mov  R3,  #0xFF
CP1:	inc  R3
		mov  A,   #0x20
		add  A,    R3
		add  A,    R2
		mov  R0,   A
		mov  B,   @R0
		mov  A,   #0x27
		add  A,    R3
  		mov  R0,   A
		mov  A,   @R0
		mul  AB
		mov  0x31, A
		mov  0x30, B
		mov  0x33, R5
		mov  0x32, R4
		lcall adder_16bit
		mov  R5,   0x36
		mov  R4,   0x35
		cjne R3,  #0x02, CP1
		mov  A,    R2
		rl   A
		add  A,    0x52
		mov  R0,   A
		mov @R0,   0x35
		inc  R0
		mov @R0,   0x36
		cjne R2,  #0x04, CP0
ret

main:	lcall init_1
		lcall init_2
		lcall convolution
here:	sjmp here
end