hsuay
3/29/2018 - 12:12 PM

dice.asm

#dice game

.data

	setCount: .word 1
	playerWinCount: .word 0
	computerWinCount: .word 0
	
	displayGroupMembers: .asciiz "Project made by:\n\t\tAYUSH MISHRA\t1641017323\n\t\tANKESH RAJ  \t1641017239\n\t\tANIKET PRASAD\t1641017275\n\t\tANKITA SARKAR\t1641017100\n\n"
	heading: .asciiz "DICE GAME\n\n"
	yourTurn: .asciiz "\n\nYour Turn\n"
	prompt: .asciiz "Enter an integer(seed - enter different number each time) to throw dice: "
	computerTurn: .asciiz "\n\nComputer's turn"
	yourResult: .asciiz "Your result: "
	computerResult: .asciiz "\nComputer's result: "
	displayScore: .asciiz "\n\nCurrent score(You - Computer): "
	displaySet: .asciiz "\n\nSet #"
	return: .asciiz "\n\n"
	results: .asciiz "FINAL SCORE:\t"
	hyphen: .asciiz " - "
	currentScore: .asciiz "\nCurrent Score: "
	enter: .asciiz "\n\n"
	computerWinPrint: .asciiz "\n\nCOMPUTER WINS!"
	playerWinPrint: .asciiz "\n\nPLAYER WINS!"
	tiePrint: .asciiz "\n\nTIED!"
	
	
	
.text
.globl main
.ent main

main: 
	
	#display authors
	li $v0, 4
	la $a0, displayGroupMembers
	syscall
	
	#display heading
	li $v0, 4
	la $a0, heading
	syscall
	
	#loop 5 times
	
	li $t0, 0 #counter variable
	li $t1, 5 #terminator
	li $t2, 1 #setCount
	li $s4, 0 #playerWinCount
	li $s5, 0 #computerWinCount
	li $s0, 0 #playerNum
	li $s1, 0 #computerNum
	li $t9, 3251 #seeeed 2
	li $s6, 6
	li $s2, 1

	
	while: 
	
		
		beq $t0, $t1, exitWhile
	
		bnez $t0, printScore
		j skipPrintScore
		printScore: 
			li $v0, 4
			la $a0, currentScore
			syscall
			
			li $v0, 1
			lw $a0, playerWinCount
			syscall
			
			li $v0, 4
			la $a0, hyphen
			syscall
			
			li $v0, 1
			lw $a0, computerWinCount
			syscall
			
			li $v0, 4
			la $a0, enter
			syscall
			
		skipPrintScore:
	
			li $v0, 4
			la $a0, displaySet
			syscall
			
			li $v0, 1
			lw $a0, setCount
			syscall
			
			li $v0, 4
			la $a0, yourTurn
			syscall
			
			li $v0, 4
			la $a0, prompt
			syscall
			
			li $v0, 5
			syscall
			move $t6, $v0 #t6 = input integer = seed
			
			li $v0, 4
			la $a0, yourResult
			syscall
			
			move $a1, $t6
			jal randomNumberGenerator	
			move $s0, $v1
			
			li $v0, 1
			move $a0, $s0
			syscall
			
			li $v0, 4
			la $a0, computerTurn
			syscall
			
			li $v0, 4
			la $a0, computerResult
			syscall
			
			move $a1, $s0		
			jal randomNumberGenerator
			move $s1, $v1
			
			li $v0, 1
			move $a0, $s1
			syscall
			
			bgt $s1, $s0, computerWins 
			beq $s1, $s0, tie
			j playerWins
			
			playerWins:
				beqz $s2, swap1
				j noSwap1
				swap1: 
					li $s2, 1
					j computerWins
				noSwap1:
					addi $s4, $s4, 1
					addi $t2, $t2, 1
					sw $s4, playerWinCount
					sw $t2, setCount
					addi $t0, $t0, 1
					j while
			
			computerWins: 
				beqz $s2, swap2
				j noSwap2
				swap2: 
					li $s2, 1
					j computerWins
				noSwap2:
					addi $s5, $s5, 1
					addi $t2, $t2, 1
					sw $s5, computerWinCount
					sw $t2, setCount
					addi $t0, $t0, 1
					j while
			
			tie: 
				addi $t2, $t2, 1
				sw $t2, setCount
				addi $t0, $t0, 1
				j while
				
			
			addi $t2, $t2, 1
			sw $t2, setCount
			addi $t0, $t0, 1
			j while
			
			
		exitWhile: 
			li $v0, 4
			la $a0, enter
			syscall
			
			li $v0, 4
			la $a0, results
			syscall
			
			li $v0, 1
			move $a0, $s4
			syscall
			
			li $v0, 4
			la $a0, hyphen
			syscall
			
			li $v0, 1
			move $a0, $s5
			syscall
			
			bgt $s4, $s5, playerWinAnnouncement
			j computerWinAnnouncement
			
			playerWinAnnouncement:
				li $v0, 4
				la $a0, playerWinPrint
				syscall
				j endProgram
				
			computerWinAnnouncement:
				beq $s4, $s5, tieAnnouncement
				li $v0, 4
				la $a0, computerWinPrint
				syscall
				j endProgram
			
			tieAnnouncement:
				li $v0, 4
				la $a0, tiePrint
				syscall
			
			endProgram:
				li $v0, 10
				syscall
		
		
.end main
	
randomNumberGenerator: 
	
	li $s2, 1
	addi $v1, $v1, 11
	mul $v1, $v1, $t0
	rem $v1, $a1, 6
	addi $v1, $v1, 1	
	rem $s7, $a1, 2
	
	jr $ra