Finish the program below that does several bitwise manipulat

Finish the program below that does several bit-wise manipulations of C integers.

Cut and paste the following:

Finish the Program!

You may only use the integer constants given at the beginning. (You may use whatever integers you wish in string constants as long as they are for printf()\'s. For example the format string \"0x%08X\" is useful for printing hexadecimal integers.)

You may only use the following integer operators:

+

-

++

--

<<

>>

~

|

&

<

>

=

!=

==

Sample output (32 bit):

Sample output (64 bit):

Solution

mm:

la $a3, array_A # base address for array_A loaded into $a3

la $a1, array_B # base address for array_B loaded into $a1

la $a2, array_C # base address for array_C loaded into $a2

li $t1, four # $t1 = four (row-size and loop end)

li $s0, zero # i = 0; initialize first for loop

loop1:

li $s1, zero # j = 0; restart 2d for loop

loop2:

li $s2, zero # k = 0; restart third for loop

sll $t2, $s0, two # $t2 = i * four (size of row of c)

addu $t2, $t2, $s1 # $t2 = i * size(row) + j

sll $t2, $t2, two # $t2 = computer memory unit offset of [i][j]

addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]

lw $t4, 0($t2) # $t4 = two bytes of c[i][j]

loop3:

sll $t0, $s2, two # $t0 = k * four (size of row of b)

addu $t0, $t0, $s1 # $t0 = k * size(row) + j

sll $t0, $t0, two # $t0 = computer memory unit offset off [k][j]

addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]

lw $t5, 0($t0) # $t5 = two bytes of b[k][j]

sll $t0, $s0, two # $t0 = i * four (size of row of a)

addu $t0, $t0, $s2 # $t0 = i * size(row) + k

sll $t0, $t0, two # $t0 = computer memory unit offset of [i][k]

addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]

lw $t6, 0($t0) # $t6 = two bytes of a[i][k]

mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]

add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]

addiu $s2, $s2, one # $k = k + one

bne $s2, $t1, loop3 #if (k != 4) attend loop3

sw $t4, 0($a2) # c[i][j] = $t4

#----------TEST-------------

li $v0, 1

lw $a0, ($a2)

syscall

li $v0, 4

la $a0, new_row

syscall

#----------TEST-------------

addiu $s1, $s1, one # $j = j + one

addi $a2, $a2, 4

bne $s1, $t1, loop2 # if (j != 4) attend loop2

addiu $s0, $s0, one # $i = i + one

bne $s0, $t1, loop1 # if (i != 32) attend L1

Exit:

li $v0, 10 #exits

syscall

    .data

    array_A: .word 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

    array_B: .word 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

    array_C: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    output_row_string_C: .asciiz \"Matrix C Output Row \"

    colon_string: .asciiz \":

mm:

la $a3, array_A # base address for array_A loaded into $a3

la $a1, array_B # base address for array_B loaded into $a1

la $a2, array_C # base address for array_C loaded into $a2

li $t1, four # $t1 = four (row-size and loop end)

li $s0, zero # i = 0; initialize first for loop

loop1:

li $s1, zero # j = 0; restart 2d for loop

loop2:

li $s2, zero # k = 0; restart third for loop

sll $t2, $s0, two # $t2 = i * four (size of row of c)

addu $t2, $t2, $s1 # $t2 = i * size(row) + j

sll $t2, $t2, two # $t2 = computer memory unit offset of [i][j]

addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]

lw $t4, 0($t2) # $t4 = two bytes of c[i][j]

loop3:

sll $t0, $s2, two # $t0 = k * four (size of row of b)

addu $t0, $t0, $s1 # $t0 = k * size(row) + j

sll $t0, $t0, two # $t0 = computer memory unit offset off [k][j]

addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]

lw $t5, 0($t0) # $t5 = two bytes of b[k][j]

sll $t0, $s0, two # $t0 = i * four (size of row of a)

addu $t0, $t0, $s2 # $t0 = i * size(row) + k

sll $t0, $t0, two # $t0 = computer memory unit offset of [i][k]

addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]

lw $t6, 0($t0) # $t6 = two bytes of a[i][k]

mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]

add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]

addiu $s2, $s2, one # $k = k + one

bne $s2, $t1, loop3 #if (k != 4) attend loop3

sw $t4, 0($a2) # c[i][j] = $t4

#----------TEST-------------

li $v0, 1

lw $a0, ($a2)

syscall

li $v0, 4

la $a0, new_row

syscall

#----------TEST-------------

addiu $s1, $s1, one # $j = j + one

addi $a2, $a2, 4

bne $s1, $t1, loop2 # if (j != 4) attend loop2

addiu $s0, $s0, one # $i = i + one

bne $s0, $t1, loop1 # if (i != 32) attend L1

Exit:

li $v0, 10 #exits

syscall

    .data

    array_A: .word 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

    array_B: .word 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

    array_C: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    output_row_string_C: .asciiz \"Matrix C Output Row \"

    colon_string: .asciiz \":mm:

la $a3, array_A # base address for array_A loaded into $a3

la $a1, array_B # base address for array_B loaded into $a1

la $a2, array_C # base address for array_C loaded into $a2

li $t1, four # $t1 = four (row-size and loop end)

li $s0, zero # i = 0; initialize first for loop

loop1:

li $s1, zero # j = 0; restart 2d for loop

loop2:

li $s2, zero # k = 0; restart third for loop

sll $t2, $s0, two # $t2 = i * four (size of row of c)

addu $t2, $t2, $s1 # $t2 = i * size(row) + j

sll $t2, $t2, two # $t2 = computer memory unit offset of [i][j]

addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]

lw $t4, 0($t2) # $t4 = two bytes of c[i][j]

loop3:

sll $t0, $s2, two # $t0 = k * four (size of row of b)

addu $t0, $t0, $s1 # $t0 = k * size(row) + j

sll $t0, $t0, two # $t0 = computer memory unit offset off [k][j]

addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]

lw $t5, 0($t0) # $t5 = two bytes of b[k][j]

sll $t0, $s0, two # $t0 = i * four (size of row of a)

addu $t0, $t0, $s2 # $t0 = i * size(row) + k

sll $t0, $t0, two # $t0 = computer memory unit offset of [i][k]

addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]

lw $t6, 0($t0) # $t6 = two bytes of a[i][k]

mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]

add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]

addiu $s2, $s2, one # $k = k + one

bne $s2, $t1, loop3 #if (k != 4) attend loop3

sw $t4, 0($a2) # c[i][j] = $t4

#----------TEST-------------

li $v0, 1

lw $a0, ($a2)

syscall

li $v0, 4

la $a0, new_row

syscall

#----------TEST-------------

addiu $s1, $s1, one # $j = j + one

addi $a2, $a2, 4

bne $s1, $t1, loop2 # if (j != 4) attend loop2

addiu $s0, $s0, one # $i = i + one

bne $s0, $t1, loop1 # if (i != 32) attend L1

Exit:

li $v0, 10 #exits

syscall

    .data

    array_A: .word 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

    array_B: .word 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

    array_C: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    output_row_string_C: .asciiz \"Matrix C Output Row \"

  colon_string: .asciiz \":

mm:

la $a3, array_A # base address for array_A loaded into $a3

la $a1, array_B # base address for array_B loaded into $a1

la $a2, array_C # base address for array_C loaded into $a2

li $t1, four # $t1 = four (row-size and loop end)

li $s0, zero # i = 0; initialize first for loop

loop1:

li $s1, zero # j = 0; restart 2d for loop

loop2:

li $s2, zero # k = 0; restart third for loop

sll $t2, $s0, two # $t2 = i * four (size of row of c)

addu $t2, $t2, $s1 # $t2 = i * size(row) + j

sll $t2, $t2, two # $t2 = computer memory unit offset of [i][j]

addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]

lw $t4, 0($t2) # $t4 = two bytes of c[i][j]

loop3:

sll $t0, $s2, two # $t0 = k * four (size of row of b)

addu $t0, $t0, $s1 # $t0 = k * size(row) + j

sll $t0, $t0, two # $t0 = computer memory unit offset off [k][j]

addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]

lw $t5, 0($t0) # $t5 = two bytes of b[k][j]

sll $t0, $s0, two # $t0 = i * four (size of row of a)

addu $t0, $t0, $s2 # $t0 = i * size(row) + k

sll $t0, $t0, two # $t0 = computer memory unit offset of [i][k]

addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]

lw $t6, 0($t0) # $t6 = two bytes of a[i][k]

mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]

add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]

addiu $s2, $s2, one # $k = k + one

bne $s2, $t1, loop3 #if (k != 4) attend loop3

sw $t4, 0($a2) # c[i][j] = $t4

#----------TEST-------------

li $v0, 1

lw $a0, ($a2)

syscall

li $v0, 4

la $a0, new_row

syscall

#----------TEST-------------

addiu $s1, $s1, one # $j = j + one

addi $a2, $a2, 4

bne $s1, $t1, loop2 # if (j != 4) attend loop2

addiu $s0, $s0, one # $i = i + one

bne $s0, $t1, loop1 # if (i != 32) attend L1

Exit:

li $v0, 10 #exits

syscall

    .data

    array_A: .word 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

    array_B: .word 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

    array_C: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

    output_row_string_C: .asciiz \"Matrix C Output Row \"

    colon_string: .asciiz \":

Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c
Finish the program below that does several bit-wise manipulations of C integers. Cut and paste the following: Finish the Program! You may only use the integer c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site