Computer:Architecture:HW1 Solution

$30.00 $24.00

Corresponding TAs: Aditya Sasongko Notes: You may discuss the problems with your peers but the submitted work must be your own work. No late assignment will be accepted. Submit a SOFT copy of your assignment to the blackboard *AND* submit a HARD copy of it to the COMP 303 mailboxes. This assignment is worth 4%…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Corresponding TAs: Aditya Sasongko

Notes: You may discuss the problems with your peers but the submitted work must be your own work. No late assignment will be accepted. Submit a SOFT copy of your assignment to the blackboard *AND* submit a HARD copy of it to the COMP 303 mailboxes. This assignment is worth 4% of your total grade.

Problem 1

(10 pts)

  1. In MIPS assembly, write an assembly language version of the following C code segment. At the beginning of the segment, the only values in registers are the base address of arrays A and B in registers $a0 and $a1. To get credit, comment your code.

  • int A[40], B[40];

  • for (i=1; i < 40; i++) {

  • B[i] = A[i] + A[i-1];

  • A[i] = 5*B[i] ;

  • }

    1. Compilers can optimize loops to reduce memory operations (loads and stores) for perfor-mance. Implement more optimized version of the above loop in assembly language that uses fewer memory instructions.

1

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 1

  • //write your code for (a) here

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

  1. //write your code for (b) here

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

  1. .

Student Name: Page 2 of 7

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 2

Problem 2

(6 pts) Suppose that you are asked to design a chip for an embedded system that will be used for gym equipment. Because of the cost and space restrictions, you decided to have 20-bit wide instructions and have only 16 general-purpose registers. Similar to MIPS, this chip uses a three-address ISA, which takes two sources, performs an operation on these sources and stores the result back into a destination register.

  1. How will your R-type instructions look like? Assume that there is no opcode extension and shift amount is represented in 3 bits.

  1. How many di erent instructions you can encode in this new ISA?

  1. How many bits should the immediate eld of an I-type instruction be to match the length on an R-type instruction?

Student Name: Page 3 of 7

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 3

Problem 3

(20 pts ) 0-address machine uses a stack, where all operations are done using values stored on the stack. For example,

PUSH addr – pushes the value stored at memory location addr onto the stack. POP addr – pops the stack and stores the value into memory location addr

BOP addr – pops two values o the stack, performs the binary operation BOP on the two values, and pushes the result back onto the stack

For example, to compute A + B with 0-address machine, the following sequence of operations are necessary: PUSH A, PUSH B, ADD. After execution of ADD, A and B would no longer be on the stack, but the value A+B would be at the top of the stack.

Make the following assumptions for the next questions and the following code snippet.

The opcode size is 1 byte (8 bits).

All register operands are 1 byte (8 bits).

All memory addresses are 2 bytes (16 bits). All data values are 4 bytes (32 bits).

All instructions are an integral number of bytes in length.

1

2

3

X=Y+Z;

Y=X+Z;

T=X-Y;

For (a), (b), (c), use the provided table. I-bytes refers to instruction bytes, D-bytes refers to data bytes.

  1. What is the assembly code for the above code for 0-address machine? Assume initially the variables X, Y, Z and T are in memory. Be sure to store the contents of variables back into memory. Do not modify any other values in memory.

  1. What is the assembly code for the above code for MIPS?

  1. Calculate the instruction bytes fetched and the memory-data bytes transferred (read or written) for 0-address machine and for MIPS.

  1. Which ISA is most e cient as measured by code size? Why?

  1. Which ISA is most e cient as measured by total memory tra c (code + data)? Why?

Student Name: Page 4 of 7

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 3

Student Name: Page 5 of 7

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 4

Problem 4

(10 pts) MIPS is just one of the Instruction Set Architectures and it is a simple one. Consider a more complex instruction set, called MAPS. One instruction in MAPS can perform the function of many instructions in MIPS. In this question, you are ask to implement the MIPS equivalent for a single instruction in MAPS, namely short int CP Y X, which is de ned as follows:

This instruction copies short integers from one address to another. The instruction uses three registers: CNT (count), SRC (source), and DST (destination). The CNT indicates the number of iterations. Each iteration, the instruction moves a short integer (two bytes data) from memory at address SRC to memory at address DST, and then increments both address pointers by two bytes. Thus, the instruction copies in total 2*CNT many bytes from source to destination.

  1. Write the corresponding MIPS code for short int CP Y X that performs the same func-tion. Assume $s1 = CNT; $s2 = SRC; $s3 = DST: Try to minimize code size as much as possible.

  • .

  • .

  • .

  • .

  • .

  • .

  • .

  • .

  • .

  1. .

  1. .

  1. .

  1. .

  1. .

  1. .

  1. .

  1. .

  1. .

b) Compare the code sizes of MIPS and MAPS for the same function in bytes. Which one is shorter?

Student Name: Page 6 of 7

COMP 303 – Computer Architecture ( Due: Oct 13, 2019, 6pm): HW1 PROBLEM 5

Problem 5

4 pts (This topic will be covered in the class soon)

Instruction Type

Machine M1

Machine M2

Instruction

Cycles/Instruction

Cycles/Instruction

Frequency

Loads/Stores

4

4

30%

ALU Operations

1

2

60%

Branches

2

1

10%

Consider two di erent implementations, Machine M1 and M2, of the same instruction set. There are three types of instructions (loads/stores, ALU operations and branches) in the instruction set. M1 has a clock rate of 800 MHz and M2 has a clock rate of 1.25 GHz. The average number of cycles for each instruction type and their frequencies for an image processing algorithm are provided in the table above.

a) Calculate the average CPI for each machine, M1 and M2.

b) Compare the CPU time of each machine for the image processing algorithm.

Computer:Architecture:HW1 Solution
$30.00 $24.00