Вы находитесь на странице: 1из 3

Name: Christophe El Haddad

ID: 201800866
Section: 2

EECE 321 – Homework 2

1) The steps to execute MAC Mem1, Mem2, Mem3 are:

 PC points to the 1st instruction of the program (MAC Mem1, Mem2, Mem3)

 The contents of PC are sent to MAR to signal a Read operation for Memory

 After “Memory-Access” time has elapsed, the instruction Word is loaded into MDR

 The contents of MDR are transferred into IR which decodes it and determine the
MAC type and the operands Mem1, Mem2 and Mem3

 The address of Mem1 is sent to MAR, and the contents of MDR are transferred to R0

 Similarly, the contents of Mem2 and Mem3 are stored respectively in R1 and R2

 The contents of R1 and R2 are sent as operands to the ALU to execute the
multiplication operation and store the result in R3

 The contents of R0 and R3 are sent as operands to the ALU to execute the add
operation and store the result in MDR with a Write control signal, and the address of
Mem1 is sent to MAR

 The PC is incremented to point to the next instruction to be executed

2) g = 1 - 2*B[i];

 sll $t0, $s3, 2

 add $t1, $t0, $s6

 lw $t0, 0($t1)

 sll $t0, $t0, 1

 addi $t0, $t0, -1

 sub $s1, $0, $t0

f = h + A[0] + B[C[1]];

 lw $t0, 0($s5)

 add $t0, $s2, $t0 // h + A[0]

 lw $t1, 4($s7) // C[1]


Name: Christophe El Haddad
ID: 201800866
Section: 2

 sll $t1, $t1, 2

 add $t1, $t1, $s6

 lw $t1, 0($t1) // B[C[1]]

 add $s0, $t0, $t1

B[i+j+C[i]] = A[i] + B[i+j+C[i-1]];

 sll $t0, $s3, 2

 add $t0, $t0, $s5

 lw $t0, 0($t0) // A[i]

 add $t1, $s3, $s4 // i + j

 addi $t2, $s3, -1

 sll $t2, $t2, 2

 add $t2, $t2, $s7

 lw $t2, 0($t2)

 add $t2, $t2, $t1

 sll $t2, $t2, 2

 add $t2, $t2, $s6

 lw $t2, 0($t2) // B[i+j+C[i-1]]

 sll $t3, $s3, 2

 add $t3, $t3, $s7

 lw $t3, 0($t3) // C[i]

 add $t1, $t1, $t3

 sll $t1, $t1, 2

 add $t1, $t1, $s6

 add $t0, $t0, $t2

 sw $t0, 0($t1)

3) $s3 = 00000000000000000000000000000101
Name: Christophe El Haddad
ID: 201800866
Section: 2

$s4 = 11111110111111101111111011111111

a) xor: $s5 = 11111110111111101111111011111010 = 0xFEFE_FEFA

sll: $s5 = 11101111111011111110111111110000 = 0xEFEF_EFF0

b) andi: $s3 = 0x1

andi: $s4 = 0xF

or: $s5 = 0xF

4) First, we must create a mask containing a 1 at the position to be flipped. Then, we store
in $s0 the result of the content of $s0 XOR the mask.

 addi $t0, $0, 1

 addi $t1, $0, 0

 Loop: beq $t1, $s1, Exit

 addi $t1, $t1, 1

 sll $t0, $t0, 1

 j Loop

 Exit: xor $s0, $s0, $t0

Another way to create the mask without using a loop (but in a memory demanding way)
is to create 32 consecutive words in memory, starting from a base address A, consisting
of 0x1, 0x2, 0x4, 0x8, 0x10, … , 0x80000000. To load a mask, we simply load the word
from the address (4*content of $s1 + A).

5)

1. The code permutes the entries of the matrix outside the main diagonal, so the
matrix becomes its transpose. Also, the code returns the maximum value of the
entries of the matrix.

2. The function returns 1 for the 10x10 identity matrix (and the new matrix A is still
the 10x10 identity matrix).

Вам также может понравиться