Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For these programming exercises, use only those instructions that have been disc

ID: 3734972 • Letter: F

Question

For these programming exercises, use only those instructions that have been discussed so far in these notes:

xori

1)

Put the following bit pattern into register $1 :

A. Easy program: do this using just three instructions.

2) Start out a program with the instruction that puts a single one-bit into register one:

Now, by using only shift instructions and register to register logic instructions, put the pattern 0xFFFFFFFF into register $1. Don't use another ori after the first. You will need to use more registers than $1. See how few instructions you can do this in. My program has 11 instructions.

and andi nor or ori sll srl xor

xori

Explanation / Answer

1)

A.

.text                      # code section

.globl main

main:

                la $1, str                               # load address of string

                .data

str:         .ascii “DEADBEEF”

---------------------------------------------

B.

.text
.globl main
main:    la $1, Aaddr    # $1 = pointer to array A
   lw $t1, len    # $t1 = length (of array A)
   sll $t1, $t1, 2    # $t1 = 4*length
   add $t1, $t1, $1    # $t1 = address(A)+4*length
loop:    lw $t2, 0($1)    # $t2 = A[i]
   addi $t2, $t2, 5    # $t2 = $t2 +8
   sw $t2, 0($1)    # A[i] = $t2
   addi $1, $1, 4    # i = i+1
   bne $1, $t1, loop    # if $1<$t1 goto loop
.data
Aaddr: .ascii "D","E","A","D", "B","E","E","F" # array with 8 elements
len: .word 8

2)