Question: Code I currently have: Task 1: Read an integer from the User Your first task is to print a message that asks the user to

 Code I currently have: Task 1: Read an integer from the

User Your first task is to print a message that asks theuser to enter a number between 0 and 10 and then readsand stores the number the user entered. Begin working in the file

Code I currently have:

template ( ca.asm ) provided in the ca folder. # Data for

the program goes here .data # Code goes here .text main: li

Task 1: Read an integer from the User Your first task is to print a message that asks the user to enter a number between 0 and 10 and then reads and stores the number the user entered. Begin working in the file template ( ca.asm ) provided in the ca folder. # Data for the program goes here .data # Code goes here .text main: li $v0, 10 syscall # 10 is the exit program syscall # execute call ## end of ca.asm In the .data directive, declare a string with the user prompt. You should also declare a memory location and store the secret value. (I chose 6). In the main procedure of your .text directive use syscalls to display the prompt and read the user input. Task 2: Compare user input Your next task is to add code to compare the user input to the secret value. If the user input is smaller than the secret value you should tell the user to guess a larger value If the user input is larger than the secret value you should tell the user to guess a smaller value If the user input is the same as the secret value you should tell the user they win. Task 3: Loop The final task is to setup Tasks 1 and 2 in a loop. You should allow the user to guess 5 times. If they do not guess the secret after 5 guesses. The loop should end. If they guess the secret value in less than 5 guesses you should end the loop early. 5 Task 4: End Game If the user lost (i.e. did not guess the secret value) you should print a message with the secret value, as well as all the numbers that the user guessed. (You will want to save their guesses in an array). If the user won (i.e. they guessed the secret value) you should print a message that they won! Remember to document your register usage and to thoroughly comment your code. # Registers used: ##... # $to - used to hold the secret value. ##... lw $t0, secret #$t0 = secret ##... Sample Output Win Mars Messages Run 110 Guess a number between 0 and 10: 1 Try a larger value Guess a number between 0 and 10: 9 Try a smaller value Guess a number between 0 and 10: 4 Try a larger value Guess a number between 0 and 10: 9 Clear Try a smaller value Guess a number between 0 and 10: 6 That's right! You Win!!! -- program is finished running -- Sample Output Win Mars Messages Run 10 Guess a number between 0 and 10: 0 Try a larger value Guess a number between 0 and 10: 10 Try a smaller value Guess a number between 0 and 10: 2 Try a larger value Guess a number between 0 and 10: 9 Clear Try a smaller value Guess a number between 0 and 10: 8 Try a smaller value Sorry the number was 6 You guessed 0 10 2 9 8 program is finished running 6 7 00 8 # # Registers used: # $a0 String address to print $vo - Syscall and return value $t0 - Store the user input $t1 - Store secret value ## 9 10 # 11 12 13 14 15 data # Data used by the program 16 17 18 19 prompt_txt: asciiz "Guess a number between 0 and 10: " try again txt: asciiz "Try a larger value " correct_txt: .asciiz "That's right! " winner_txt: .asciiz "You Win!!! " try_higher_txt: asciiz "Try a larger value " try_smaller_txt: asciiz "Try a smaller value 20 21 22 23 24 25 NN secret_value: word 7 .align 2 items: space 40 26 27 28 text # Instructions/code of the actual program 29 30 31 .globl main main: li $t2, 0 32 # $t2 = 0; index 31 mm 32 # $t 2 = 0; index 33 main: li $t2, 0 input_loop: la Sal, prompt_txt li $v0, 4 syscall 34 # print the prompt 35 36 37 38 #read the input 39 40 li $v0, 5 syscall move $to, $vo sw $t0, items ($t2) addi $t2, $t2, 4 41 #store input into array # $t 2 $t2 + 4 42 43 44 #compare Guess with value (Sto) 45 46 lw $ti, secret_value beg $t0,$t1, correct #load the secret value into $t1 # if $t0 == secret_value: 47 48 49 #end of loop # print correct_txt 50 j input_loop #la Sal, correct_txt #li $v0, 4 #syscall 51 52 53 54 55 5 56 57 correct: la $al, correct_txt li $v0, 4 syscall end input: exit: #exit the program using syscall 10 li $v0, 10 syscall 58 59 exit 60 61 62 a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!