Miterm q2 solution Question Write RISC-V assembly program to do this (assuming data is 32-bit integer): Count the number of odd integer in an array of positive integer. The array is terminated by -1. You can use any tools. Submit your code and write explanation of your code. Solution This array is a variable length (ako string in C). To find its length, you scan each element until find the terminator (-1). One way test for terminate is to use "branch if it is less than 0". You can also use "branch if equal -1" but you need some way to put -1 into a register. To test an integer odd or even, check the least significant bit, if it is "0" the number is even. To do that you can "bitwise and" the number with 1, if the result is "1" then it is odd. pseudo code count = 0 i = 0 while ax[i] >=0 if (ax[i] & 1) > 0 count = count + 1 // count odd number i = i + 1 now translate that into RISC-V code assume array ax[.] is at 64 (40 hexadecimal) let x5 - count x7 - i x8 - base address of ax[.] x9 - store value of ax[i] x10 - temp addi x5, x0, 0 # count = 0 addi x7, x0, 0 # i = 0 loop: lw x9, 64(x7) # get ax[i], element is 32-bit blt x9, x0, exit # branch if less than zero andi x10, x9, 1 # ax[i] & 1 beq x10, x0, even addi x5, x5, 1 # odd, count + 1 even: addi x7, x7, 4 # next i, offset 4 bytes j loop exit: If you want to run this program in Venus, you need to set memory (after assemble program). To do so, go to memory tab. ax[.] starts at 40 hex, each number is 32-bit. In this picture, I set it to 7,8,9,-1. To set -1, you enter -1 in all bytes at address 4C (they will display as FF). The above example, there are 2 odd numbers, so after the run, you get 2 in x5 and the program stops.