Question: this is my code could you help fix part b of this code please # Part A: Initialize and calculate array A [ ] addi

this is my code could you help fix part b of this code please # Part A: Initialize and calculate array A[]
addi $7, $0,366 # $7 init to x =366
addi $8, $0,466 # $8 init to y =466
sw $7,0x2020($0) # a[0]= x
sw $8,0x2024($0) # a[1]= y
lw $9,0x2020($0) # load a[0] into $9
lw $10,0x2024($0) # load a[1] into $10
li $11,2 # initialize loop counter
loop:
sub $12, $9, $10 # $12= a[i]- a[i+1]
sub $12, $12, $10 # $12= a[i]-2*a[i+1]
sll $13, $11,2 # $13= $11*4(byte offset)
addi $13, $13,0x2020 # add base address
sw $12,0($13) # store result in memory
move $9, $10 # update registers for next iteration
move $10, $12
addi $11, $11,1 # increment loop counter
bne $11,16, loop # loop until 16 elements are stored
# Part B: Calculate alphabet-count for each element in A[] and store in B[]
addi $14, $0,0x2060 # base address for array B[]
li $11,0 # loop counter
count_loop:
sll $13, $11,2 # calculate offset (i *4)
addi $13, $13,0x2020 # add base address of A[]
lw $12,0($13) # load a[i] into $12
li $15,0 # initialize alphabet-count to 0
li $16,8 # number of hex digits to check
hex_loop:
andi $17, $12,0xf # extract the least significant hex digit
bge $17,10, increment_count # if digit >=10, increment count
j skip_increment # if digit 10, skip increment
increment_count:
addi $15, $15,1 # increment alphabet-count
skip_increment:
srl $12, $12,4 # shift right to process the next hex digit
subi $16, $16,1 # decrement hex digit counter
bnez $16, hex_loop # repeat for all hex digits
sll $13, $11,2 # calculate offset (i *4)
add $13, $13, $14 # add base address of B[]
sw $15,0($13) # store b[i] in memory
addi $11, $11,1 # increment loop counter
li $18,16 # number of elements in array A[]
bne $11, $18, count_loop # loop until all elements are processed
In the image for the data segment in MARS, the addresses 0x00002060 through 0x00002080 shows 1,1,8,1,6,1,7,3,7,2,4,3,5,1,4,2 but the values are supposed to be B[0]=0 B[1]=0 B[2]=1 B[3]=0 B[4]=0 B[5]=1 B[6]=2 B[7]=2 B[8]=1 B[9]=1 B[10]=1 B[11]=1 B[12]=1 B[13]=3 B[14]=4 B[15]=4, so the values for addresses 0x00002060 through 0x00002080 should be 0,0,0,0,1,2,2,1,1,1,1,3,4,4 please help fix this Part (B) alphabet-count Array B[]: Find the alphabet-count of each number in array A[] to form a new array B[], and store it at M[0x2060,0x2064,...]. o Definition of alphabet-count B(n) of a 32-bit number n: The number of occurrences of A to F in the 8-digit hex representation (equivalent to the 32-bit binary representation) of number n: For example, if n =0x01A98FB7, then B(n)=3, because A,F,B are viewed as alphabets, occurring a total of 3 times.
this is my code could you help fix part b of this

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 Programming Questions!