| 1 | .data |
| 2 | |
| 3 | Welcome1: |
| 4 | .ascii "\n Hello! you are about to play the mastermind" |
| 5 | .ascii " guessing and logic game,Bulls & Cows!\n" |
| 6 | .ascii "The Computer will generate a secret number made of 4 unique" |
| 7 | .ascii " integer numbers. You have to guess the number!\n" |
| 8 | .ascii "Using the number of Bulls and Cows you get to find out what" |
| 9 | .asciiz " the secret number is!\n" |
| 10 | |
| 11 | Welcome2: |
| 12 | .ascii "\nEvery digit you enter that is both correct and in the right" |
| 13 | .ascii " location is a BULL. When you get 4 BULLS, YOU WIN!\n\n" |
| 14 | .ascii "Every digit you enter that is correct, but not in the right" |
| 15 | .asciiz " location is a COW!\n" |
| 16 | |
| 17 | confirm: |
| 18 | .ascii "\n Select \n" |
| 19 | .ascii "YES - if you are ready to guess\n" |
| 20 | .ascii "NO - to see the rules again\n" |
| 21 | .asciiz "Cancel - to exit the Game\n" |
| 22 | |
| 23 | msg_asknum: |
| 24 | .asciiz "\nEnter your game choice\n" |
| 25 | |
| 26 | .text |
| 27 | |
| 28 | main: |
| 29 | |
| 30 | # show intro and rules |
| 31 | main_welcome: |
| 32 | la $a0,Welcome1 |
| 33 | li $a1,1 |
| 34 | li $v0,55 |
| 35 | syscall |
| 36 | |
| 37 | la $a0,Welcome2 |
| 38 | li $v0,55 |
| 39 | syscall |
| 40 | |
| 41 | # ask user to select an action (i.e. enter data, reread rules, exit program) |
| 42 | main_confirm: |
| 43 | la $a0,confirm |
| 44 | li $v0,50 |
| 45 | syscall |
| 46 | |
| 47 | # the return is in a0: 0=yes, 1=no, 2=cancel |
| 48 | beq $a0,0,main_asknum |
| 49 | beq $a0,2,main_exit |
| 50 | b main_welcome |
| 51 | |
| 52 | # ask user for the next game input |
| 53 | # NOTE: this is a prompt for an integer number |
| 54 | main_asknum: |
| 55 | li $v0,51 |
| 56 | la $a0,msg_asknum |
| 57 | syscall |
| 58 | |
| 59 | beq $a1,-1,main_asknum # syntax error |
| 60 | beq $a1,-2,main_confirm # cancel |
| 61 | beq $a1,-3,main_asknum # ok, but no data |
| 62 | |
| 63 | jal do_something # do something with the number in a0 ... |
| 64 | |
| 65 | j main_asknum |
| 66 | |
| 67 | main_exit: |
| 68 | li $v0,10 |
| 69 | syscall |
| 70 | |
| 71 | # do_something -- process user's input |
| 72 | # |
| 73 | # arguments: |
| 74 | # a0 -- number the user entered |
| 75 | do_something: |
| 76 | jr $ra # return |