If the number is 10 then the number is reset to 10 The user is then asked to

If the number is 10 then the number is reset to 10

This preview shows page 1 - 3 out of 4 pages.

# number is reset to 0. If the number is > 10, then the # number is reset to 10. The user is then asked to enter# the numbers which are read into the array. The count is# returned.# parameters: $a0 base address of array# return value: $v0 count of numbers enteredreaddata:addi $sp, $sp, -8#allocate for 2 registerssw $s0, ($sp)#save $s0sw $s1, 4($sp)#save $s1move $t0, $a0#copy start of array
li $v0, 4#set command to print stringla $a0, prompt1 #get start of stringsyscallli $v0, 5#set command to read integersyscall#read into $v0move $s0, $v0#get countbge $s0, $0, next1#if count >= 0, go to next checkandi $s0, $s0, 0#set count to 0j cont#skip next testsnext1:li $t1, 10ble $s0, $t1, cont#if count <= 10, continuemove $s0, $t1#if count > 10, set count to 10cont:andi $s1, $s1, 0#set index to 0topfor:bge $s1, $s0, ret#while index < countli $v0, 4#set command to print stringla $a0, prompt2#get start of promptsyscall#print promptli $v0, 5#get command to read integersyscall#read into $v0sll $t1, $s1, 2#index * 2add $t1, $t0, $t1#get addresssw $v0, ($t1)#store into arrayaddi $s1, $s1, 1#index++j topfor#repeatret:move $v0, $s0#set return value lw $s0, ($sp)#restore valuelw $s1, 4($sp)#restore valueaddi $sp, $sp, 8 #restore stackjr $ra#return# print

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture