
	.LIST
	.ASECT
	.=001000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
START:
	;jmp MathOps		;Neg CPL Swap 
	;jmp LogOps			;Logical Ops (AND XOR OR)
	;jmp BitShifts		;Bitshifts
	jmp BitSh2			;More Bitshifts
	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		

MathOps:
	mov #0,r1
	mov #255.,r0
	call MonB0
	swab r0			;Swap bytes of R0
	call MonB0
	swab r0			;Swap bytes of R0
	call MonB0
	call NewLine
	
	mov #0,r0
	
	mov #177777,r1
	call MonB01
	tst r1			;Get Sign flag of R1
	sxt r0			;Sign Extend R0 with Sign
	call MonB01
	mov #077777,r1
	call MonB01
	tst r1			;Get Sign flag of R1
	sxt r0			;Sign Extend R0 with Sign
	call MonB01
	call NewLine
	
	mov #3,r0
	mov #3,r1
	call MonB01
	com r0			;Flip bits of r0 (Compliment)
	neg r1			;Negate r0
	call MonB01
	call NewLine
	
	JMP infloop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
TstVals:				;Test Values for the Logical Ops
	mov #77003,r0
	mov #77003,r1
	mov #07077,r2
	mov #10567,r3
	call MonB23
	call MonB01
	return
	
LogOps:
;XOR/EOR
	call TstVals		;Init Test Values
	xor r0,r2			;XOR R0 with R2, store results in R2
	xor r1,r3			;XOR R1 with R3, store results in R3
	call MonB23
	call NewLine
	
;BIS/OR 
	call TstVals		;Init Test Values
	bis r0,r2			;set R0 Bits in R2 (result in R2)
	bis r1,r3			;set R1 Bits in R3 (result in R3)
	call MonB23
	call NewLine
	
;BIC
	call TstVals		;Init Test Values	
	bic r0,r2			;Clear R0 Bits in R2 (result in R2)
	bic r1,r3			;Clear R1 Bits in R3 (result in R3)
	call MonB23
	call NewLine
	
;AND	
	mov #^x12E,r0	;To do AND - Flip Bits and use BIC
	mov #^x12F,r1	;We want to AND these values
	mov #07077,r2
	mov #10567,r3
	call MonB23
	call MonB01
	
	com	r0			;Flip bits in R0 (compliment)
	mov #^c^x12F,r1 ;^c = Compliment (flip bits)
	call MonB01
	
	bic r0,r2		;Effective R2= R2 AND R1
	bic r1,r3		;Effective R3= R3 AND R0
	call MonB23
	call NewLine
	
	JMP infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
BitShifts:
	mov #057253,r0
	call MonF0
		
	mov #3,r1		;Loop Count
Loop1:
	ror r0			;Rotate R0 right, bit 0 pushed to Carry Flag
	call MonF0
	sob r1,Loop1	;Dec R1, and repeat until zero

	call newline
	call MonF0
	
	mov #3,r1		;Loop Count
Loop2:
	rol r0			;Rotate R0 left, bit 15 pushed to Carry Flag
	call MonF0
	sob r1,Loop2	;Dec R1, and repeat until zero

	call newline
	call MonF0

	mov #3,r1		;Loop Count
Loop3:
	asr r0			;Arithmatic shift right(bit 15 stays same)
	call MonF0
	sob r1,Loop3
	
	call newline
	call MonF0
	
	mov #3,r1		;Loop Count
Loop4:
	asl r0			;Arithmatic Shift left (bit 0 stays the same)
	call MonF0
	sob r1,Loop4	;Dec R4, and repeat until zero
	
	JMP infloop

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	

BitSh2:	
	mov #057253,r0
	;mov #2,r1		;Move Left in 2's 	
	mov #-2,r1		;Move Right in 2's 
	call MonF10
	
	mov #7,r4		;Loop Count
Loop5:
	ash r1,r0		;Arithmatic Shift R0 left R1 bits
	
	call MonF10		;Show results
	sob r4,Loop5	;Dec R4, and repeat until zero

	call newline

	mov #057253,r0	
	mov #053232,r1
	call MonF10
	
	mov #7,r4		;Loop Count
Loop6:
	ashc #2,r0		;Move Left in 2's (32 bit regpair)
	call MonF10
	sob r4,Loop6	;Dec R4, and repeat until zero
	
	JMP infloop
	

infloop:
	JMP infloop
		

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
		
	
	.INCLUDE /Funct.mac/
	.INCLUDE /Monito.mac/
	
MonB0:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
	
		mov #'0,r1
		mov r0,r2
		jsr PC,MONREG		
		call ShowBits
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC	
		
MonB1:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
		mov r1,r2
		mov r1,-(sp)
			mov #'1,r1
			jsr PC,MONREG
		mov (sp)+,r0
		call ShowBits
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC	
MonB01:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
		mov r1,-(sp)
			mov #'0,r1
			mov r0,r2
			jsr PC,MONREG		
			call ShowBits
			
		mov (sp)+,r1
		mov r1,r2
		mov r1,-(sp)
			mov #'1,r1
			jsr PC,MONREG
		mov (sp)+,r0
		call ShowBits
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC	
MonB23:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
		
		mov #'2,r1
		jsr PC,MONREG		
		mov r2,r0
		call ShowBits
			
		mov r3,r2		
		mov #'3,r1
		jsr PC,MONREG
		mov r3,r0
		call ShowBits
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC		
	
ShowBits:
	mov r0,-(sp)
	mov r1,-(sp)	
		call DoBit
		mov #5,r4
ShowB3:
		mov r0,-(sp)
			mov #' ,r0
			jsr PC,PrintChar
		mov (sp)+,r0
		mov #3,r5
ShowA3:
		call DoBit
		sob r5,ShowA3
		
		sob r4,ShowB3
		mov #' ,r0
		jsr PC,PrintChar
		jsr PC,PrintChar
	mov (sp)+,r1
	mov (sp)+,r0
	RTS PC


	
DoBit:
	

	mov r5,-(sp)
	mov r4,-(sp)
	mov r2,-(sp)
	mov r1,-(sp)	
	
		mov r0,r5
		rol r5
		mov r5,-(sp)
			mov #'0,r0
			bcc DoBit0
			mov #'1,r0
	DoBit0:	
			jsr PC,PrintChar
		mov (sp)+,r0
	
	mov (sp)+,r1
	mov (sp)+,r2
	mov (sp)+,r4
	mov (sp)+,r5
	RTS PC
	
MonR01:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
		mov r1,-(sp)
			mov #'0,r1
			mov r0,r2
			jsr PC,MONREG		
		mov (sp)+,r1
		mov r1,r2
		mov #'1,r1
		jsr PC,MONREG
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC

MonR0:
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)	
		mov #'0,r1
		mov r0,r2
		jsr PC,MONREG		
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	RTS PC

;-------------------------------------------------------------------------------
MonF10:
	mfps r5
	mov r5,-(sp)
	mov r4,-(sp)
	mov r3,-(sp)
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
	
		mov r0,-(sp)
			mtps r5		
			call MonFlg
			mov #' ,r1
			
			call PrintChar
			mov #'0,r1
		mov (sp)+,r2
		mov r2,-(sp)
			jsr PC,MONREG		
		mov (sp)+,r0
		call ShowBits
	
		
	mov (sp)+,r0
	mov (sp)+,r1
	mov r1,-(sp)	
	mov r0,-(sp)
		mov r1,-(sp)
			mov #'1,r1
		mov (sp)+,r2
		mov r2,-(sp)
			jsr PC,MONREG		
		mov (sp)+,r0
		call ShowBits
		call NewLine
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	mov (sp)+,r3
	mov (sp)+,r4
	mov (sp)+,r5
	mtps r5
	RTS PC	
MonF0:
	mfps r5
	mov r5,-(sp)
	mov r2,-(sp)
	mov r1,-(sp)	
	mov r0,-(sp)
	
		mov r0,-(sp)
			mtps r5		
			call MonFlg
			mov #' ,r0
			call PrintChar
			mov #'0,r1
		mov (sp)+,r2
		mov r2,-(sp)
			jsr PC,MONREG		
		mov (sp)+,r0
		call ShowBits
		call NewLine
	
		
	mov (sp)+,r0
	mov (sp)+,r1
	mov (sp)+,r2
	mov (sp)+,r5
	mtps r5
	RTS PC	

MonFlg:
	mfps r5
	
	mov #'N,r0
	bitb #^b00001000,r5
	bne FlagN
	mov #'-,r0
FlagN:
	call PrintChar
	mov #'Z,r0
	bitb #^b00000100,r5
	bne FlagZ
	mov #'-,r0
FlagZ:
	call PrintChar
	mov #'V,r0
	bitb #^b00000010,r5
	bne FlagV
	mov #'-,r0
FlagV:
	call PrintChar
	
	mov #'C,r0
	bitb #^b00000001,r5
	bne FlagC
	mov #'-,r0
FlagC:
	call PrintChar
	mov #' ,r0
	call PrintChar
	mtps r5
	return
	

	.EVEN			
;Space for Stack - Stack starts at end of program
	.BLKB 128.	

	.END    START
