assignment 4 - comp228

3
CONCORDIA UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING COMP 228 Fall 2009 ASSIGNMENT 4 Due: November 19, 2009 1. Comparison of Different Architectures [24%] Consider the coding of the assignment statement Z = (X-Y)*(X-Z) into a 2-address and a 3-address machine respectively. Both machines support register, register indirect and direct memory addressing. Specifically, r1 specifies that the operand is in register r1, [r1] specifies that the operand is in memory whose address is in r1, and [X] specifies that the operand is from memory address X. Both machines have multiple registers, say r1 to r8. The instruction formats of these two machines have the following details: (i) a register or register indirect operand (i.e. r1 or [r1]) is specified using a half-byte (4 bits), (ii) a direct memory address (i.e. X) is specified using 2 bytes, (iii) an opcode is 1 byte, and (iv) the length of an instruction is an integer number of bytes. The following versions of programs are already written: 2-address version: mov r1, [X] sub r1, [Y] mov r2, [X] sub r2, [Z] mul r1, r2 mov [Z], r1 3-address version: sub r1, [X], [Y] sub r2, [X], [Z] mul [Z], r1, r2 (a) Determine the (i) total number of bytes needed to store each program version, and (ii) the total number of memory operand accesses (read or write) in executing each program. (b) Rewrite the two programs so that the total number of memory operand fetches in each is minimized. (c) Compare the two given versions in (i) code size, (ii) execution efficiency (number of memory operand fetches and number of instructions executed). Which version would you prefer? (d) Write the corresponding program code for a stack computer.

description

2-address version: mov r1, [X] sub r1, [Y] mov r2, [X] sub r2, [Z] mul r1, r2 mov [Z], r1 3-address version: sub r1, [X], [Y] sub r2, [X], [Z] mul [Z], r1, r2 The following versions of programs are already written: main mov ecx, list-4 call count cont ::::::: COMP 228 (System Hardware), Fall 2008 ⎯ Assignment 4 Page 2

Transcript of assignment 4 - comp228

Page 1: assignment 4 - comp228

CONCORDIA UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING

COMP 228 Fall 2009 ASSIGNMENT 4

Due: November 19, 2009 1. Comparison of Different Architectures [24%]

Consider the coding of the assignment statement Z = (X-Y)*(X-Z) into a 2-address and a 3-address machine respectively. Both machines support register, register indirect and direct memory addressing. Specifically, r1 specifies that the operand is in register r1, [r1] specifies that the operand is in memory whose address is in r1, and [X] specifies that the operand is from memory address X. Both machines have multiple registers, say r1 to r8. The instruction formats of these two machines have the following details: (i) a register or register indirect operand (i.e. r1 or [r1]) is specified using a half-byte

(4 bits), (ii) a direct memory address (i.e. X) is specified using 2 bytes, (iii) an opcode is 1 byte, and (iv) the length of an instruction is an integer number of bytes. The following versions of programs are already written: 2-address version: mov r1, [X] sub r1, [Y] mov r2, [X] sub r2, [Z] mul r1, r2 mov [Z], r1 3-address version: sub r1, [X], [Y] sub r2, [X], [Z] mul [Z], r1, r2

(a) Determine the (i) total number of bytes needed to store each program version, and (ii)

the total number of memory operand accesses (read or write) in executing each program. (b) Rewrite the two programs so that the total number of memory operand fetches in each

is minimized. (c) Compare the two given versions in (i) code size, (ii) execution efficiency (number of

memory operand fetches and number of instructions executed). Which version would you prefer?

(d) Write the corresponding program code for a stack computer.

Page 2: assignment 4 - comp228

COMP 228 (System Hardware), Fall 2008 ⎯ Assignment 4 Page 2

2. NA SM Program Analysis [24%] Consider the following given NASM program fragment. Starting from symbolic location list is a sequence of ASCII characters.

main mov ecx, list-4 call count

cont ::::::: count push edx

xor eax, eax mov edx, [ecx]

jz done add ecx, 4 again cmp byte[ecx], 32 jnz next inc eax next inc ecx

dec edx jnz again done pop edx ret Suppose the content of memory location [list – 4] is 24 and the sequence of characters

stored starting from symbolic location list is ‘Welcome World! You are going to have a fun time.’ (i) How many bytes of memory operand is involved in the instruction mov edx,

[ecx]? (ii) How many bytes of memory operand is involved in the instruction cmp byte[ecx],

32? (iii) How many times is the instruction at memory location ‘again’ executed? (iv) What is the value stored in register ecx when the instruction ret is executed? (v) What is the value stored in register eax when the instruction ret is executed? (vi) What is the function performed by the subroutine count? (vii) Identify the immediate operand(s) that are used in the given program. (viii) Determine the total number of memory operand fetches that occur during the

execution of the program.

Page 3: assignment 4 - comp228

COMP 228 (System Hardware), Fall 2008 ⎯ Assignment 4 Page 3

3. Pipelining [22%]

A pipelined MARIE processor is implemented with the following details. The instruction cycle is ‘pipelined’ to consist of four stages: (i) F (instruction fetch), (ii) D (instruction decode), (iii) M (load from or store to memory), and (iv) X (arithmetic instruction executon). Each stage takes one cycle, except for the AddI instruction which requires 2 cycles to complete the M stage. This is because AddI requires two memory read operations to fetch the operand.

(a) Determine the total number of clock cycles needed to execute the following sequence of MARIE instructions:

Load X AddI Y Store Z [Hint: Recall that an operand must be produced before it can be consumed/used by a

following instruction.] (b) What is the ideal (maximum) speedup of the given MARIE processor? (c) Give three reasons why the ideal speedup in (b) may not be achievable in practice. 4. NASM Programming [Do this problem in the lab.] [30%] Write a NASM program that does the following:

(i) prompts the user to input a line, (ii) deletes all occurrences of the vowel ‘a’, (iii) echoe the resulting line to the output. Assemble your program using the NASM assembler and run the resulting executable. Debug the program until it works correctly. Submit a correctly working version of your NASM program along with its output illustrating its correctness. [Hint: Refer to the program in (2) above and the Hello World program discussed in class for reuse/assistance.]