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

ANSWER THE PROBLEMS THAT YOU CAN. Problem 1. [5 points] Write the following sequ

ID: 3621382 • Letter: A

Question

ANSWER THE PROBLEMS THAT YOU CAN.

Problem 1. [5 points] Write the following sequence of code into NIOS-II
assembly code:

x = x + y + z - q;
Assume that x, y, z, q are stored in registers $1-$4.


Problem 2. [10 points]

In NIOS-II assembly, write an assembly language version of the following
C code segment:

int A[100], B[100];
for (i=1; i < 100; i++) {
A[i] = A[i-1] + B[i];
}
1G

At the beginning of this code segment, the only values in registers
are the base address of arrays A and B in registers $1 and $2. Avoid
the use of multiplication instructions.they are unnecessary.


Problem 3. [6 points] The NIOS-II instruction set includes several shift
instructions. They include logical-shiftleft, logical-shift-right, and
arithmetic-shift-right. Other architectures only provide an
arithmeticshift- right instruction.


a) Why doesn't NIOS-II offer an .arithmetic-shift-left. opcode?



b) How would you implement in the assembler a logical-shift-left (LSL)
pseudo-operation for a machine that didn.t have this particular
instruction? Be sure your LSL instruction can shift up to W-bits where
W is the machine word size in bits.






Problem 4. [5 points] In the snippet of NIOS-II assembler code below, how
many times is instruction memory accessed? How many times is data
memory accessed? (Count only accesses to memory, not registers.)

lw $v1, 0($a0)
addi $v0, $v0, 1
sw $v1, 0($a1)
addi $a0, $a0, 1


Problem 5. [6 points] Use the register and memory values in the table
below for the next questions. Assume a 32-bit machine. Assume each of
the following questions starts from the table values; that is, DO NOT
use value changes from one question as propagating into future parts
of the question.

Register Value Memory Location Value
R1 12 12 16
R2 16 16 20
R3 20 20 24
R4 24 24 28


a) Give the values of R1, R2, and R3 after this instruction: add R3,
R2, R1

b) What values will be in R1 and R3 after this instruction is
executed: load R3, 12(R1)

c) What values will be in the registers after this instruction is
executed: addi R2, R3, #16



Problem 6. [10 points] In NIOS-II assembly, write an assembly language
version of the following C code segment:


for (i = 0; i < 98; i ++) {
C[i] = A[i + 1] - A[i] * B[i + 2]
}

Arrays A, B and C start at memory location A000hex, B000hex and
C000hex respectively. Try to reduce the total number of instructions
and the number of expensive instructions such as multiplies.


Problem 7. [10 points] Re-write the following switch statement in NIOS-II
assembly code. Assume that x,a,b,c are held within registers $1,$2,$3,$4.


switch (x) {
case 0:
a = b + c;
break;
case 1:
a = b - c;
break;
case 2:
a = b << c;
break;
case 3:
a = b >> c;
break;
default:
a = 0;
}

Problem 8. [20 points]

Write an assembly language program using the NIOS-II instruction set
which does the same job as the following piece of C code:

int a[n][m];
acc = 0;

for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
acc += a[i][j];
}
}

Assume that the first element of the array is stored at memory
location Astart. The array is stored in the row major form, i.e., all
the elements are stored in successive memory locations in the
following order: a[0][0], a[0][1], a[0][2], a[0][3], a[0][4], a[1][0],
... , a[1][4], a[2][0], ... , a[2][4], ..., a[4][4]. Also, assume that
n and m are stored in registers $1 and $2, respectively.

Explanation / Answer

Dear, Here is the code 1. mov rx, $1 mov ry, $2 mov rz, $3 mov rq, $4 add rx,ry add rx,rz sub add rx,rq Hope this will help you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote