
.globl __start

.eqv  test,3

.include "..\\SrcAll\BasicMacros.asm"

.macro MonitorA0A1RAPCm
	push $ra
		move $t6,$ra
		jal MonitorA0A1RAPC
	pop $ra
.end_macro
.macro DumpStack
	jal MonitorA0A1PCSP

	li $t6,2			#;Line Count
	jal MemDumpNoLabel	#;Dump Stack to screen
	jal NewLine
	
.end_macro
.text
__start:
	li $ra,0

	#;j StackTest
	
	#;j TestEqualsNotequals #;= !=
	#;j TestLessGreaterUnsigned #;< <= > >=
	#;j TestLessGreaterSigned #;< <= > >=
	j TestLessGreaterZero	#;<0 <=0 >0 >=0
	
	
	
StackTest:
	move $t7,$sp		#;Address
	addi $t7,$t7,-16
	
	li $a0,0xF4F3F2F1
	DumpStack		#;Dump Stack to screen
	
	addi $sp,$sp,-4	#;push a0
	sw $a0,0($sp)    	#;push a0
		li $a0,0
		DumpStack	#;Dump Stack to screen
		jal SubTest
	lw $a0,0($sp)		#;pop a0
	addi $sp,$sp,4	#;pop a0
	
	DumpStack		#;Dump Stack to screen
	jal MonitorA0A1PCSP	
	j Shutdown

SubTest:
	addi $sp,$sp,-4		#;push ra
	sw $ra,0($sp)   		#;push ra
		li $a0,0x11223344
		push $a0
			DumpStack	#;Dump Stack to screen
		pop $a0
		DumpStack		#;Dump Stack to screen
		
	lw $ra,0($sp)			#;pop ra
	addi $sp,$sp,4		#;pop ra
	jr $ra
	
	
	
	
#; These have psuedo-ops: BEQZ, BNEZ, BLEZ, BGEZ, BLTZ, BGTZ	
TestLessGreaterZero:
	#;li a0,-100		#;TestVal1
	li $a0,0				#;TestVal1

	jal MonitorA0A1
	
	beq $a0,$zero,PrintEquals		#;Compare a0 to zero (x0 register)
	bne $a0,$zero,PrintNotEquals	#;Compare a0 to zero (x0 register)
	
	#;blt $a0,$zero,PrintLessThan			#;is a0 < zero (x0 register)
	#;bgt $a0,$zero,PrintGreaterThan		#;is a0 > zero (x0 register)

	#;ble $a0,$zero,PrintLessThanEquals		#;is a0 <= zero (x0 register)
	#;bge $a0,$zero,PrintGreaterThanEquals	#;is a0 >= zero (x0 register)
	
	j Shutdown

	
TestLessGreaterSigned:
	li $a0,-100			#;TestVal1

	li $a1,99			#;Less Than Test
	 #;li $a1,-100		#;Equals Test
	#;li $a1,-101		#;Greater than Test
	
	jal MonitorA0A1
	
	#;blt $a0,$a1,PrintLessThan			#;is a0 < a1
	#;bgt $a0,$a1,PrintGreaterThan		#;is a0 > a1

	ble $a0,$a1,PrintLessThanEquals		#;is a0 <= a1
	bge $a0,$a1,PrintGreaterThanEquals	#;is a0 >= a1
	
	j Shutdown

	
	
TestLessGreaterUnsigned:
	li $a0,100			#;TestVal1

	li $a1,99			#;Less Than Test
	#; li $a1,100		#;Equals Test
	li $a1,101			#;Greater than Test
	
	jal MonitorA0A1
	
	#;bltu $a0,$a1,PrintLessThan			#;is a0 < a1
	#;bgtu $a0,$a1,PrintGreaterThan		#;is a0 > a1
	
	bleu $a0,$a1,PrintLessThanEquals		#;is a0 <= a1
	bgeu $a0,$a1,PrintGreaterThanEquals	#;is a0 >= a1
	
	j Shutdown

	
TestEqualsNotequals:
	li $a0,100			#;TestVal1

	#; li a1,100		#;Equals Test
	li $a1,101			#;Not Equals Test
	
	jal MonitorA0A1
	
	beq $a0,$a1,PrintEquals		#;Compare a0 to a1
	bne $a0,$a1,PrintNotEquals	#;Compare a0 to a1
	
	j Shutdown
	
Shutdown:
	#; ends the program with status code 0
	li $v0, 10          
	syscall
 
PrintNotEquals:
	push $ra
		li $a1,'!'
		jal PrintChar
		li $a1,'='
		jal PrintChar
	pop $ra
	j Shutdown
PrintEquals:
	push $ra
		li $a1,'='
		jal PrintChar
	pop $ra
	j Shutdown
PrintLessThan:
	push $ra
		li $a1,'<'
		jal PrintChar
	pop $ra
	j Shutdown
PrintLessThanEquals:
	push $ra
		li $a1,'<'
		jal PrintChar
		li $a1,'='
		jal PrintChar
	pop $ra
	j Shutdown
PrintGreaterThan:
	push $ra
		li $a1,'>'
		jal PrintChar
	pop $ra
	j Shutdown
PrintGreaterThanEquals:
	push $ra
		li $a1,'>'
		jal PrintChar
		li $a1,'='
		jal PrintChar
	pop $ra
	j Shutdown


MonitorA0A1:
	push $ra
	pushAs
	    li $t5,'a'
		li $t6,'0'
		move $t7,$a0
		jal ShowRegTextB             
		li $t5,'a'
		li $t6,'1'
		move $t7,$a1
		jal ShowRegTextB             
		jal NewLine         
	popAs
	pop $ra
	jr $ra

MonitorA0A1PCSP:
	move $t4,$sp
	addi $t4,$t4,4
	push $ra
	pushAs
		push $t4
			push $ra
				li $t5,'a'
				li $t6,'0'
				move $t7,$a0
				jal ShowRegTextB             #   ;A5 A6 : A7
				li $t5,'a'
				li $t6,'1'
				move $t7,$a1
			jal ShowRegTextB             #   ;A5 A6 : A7
			li $t5,'p'
			li $t6,'c'
			pop $t7
			jal ShowRegTextB             #   ;A5 A6 : A7
			li $t5,'s'
			li $t6,'p'
		pop $t7
		jal ShowRegTextB             #   ;A5 A6 : A7
		
	popAs
	pop $ra
	jr $ra
  
.include "..\\SrcAll\monitor.asm"  
.include "..\\SrcAll\BasicFunctions.asm"  
  
#;All Data must go in the Data Segment - cannot read from code segment
.data