assignment 3 - comp228

2
CONCORDIA UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING COMP 228 Fall 2009 ASSIGNMENT 3 Due: November 3, 2009 ___________________________________________________________________________________ 1. MARIE architecture [28%] (a) The registers PC, AC, InREG, OutREG are relevant to the state of a program in the MARIE ISP. Identify which of these registers are modified when each of the following instructions are executed: (i) Load X, (ii) Subt X, (iii) Input, (iv) Halt, (v) Skipcond, (vi) Jump X, (vii) Jns X, (viii) AddI X. (b) Suppose initially PC = 100, AC = 1234, M[200] = 234 , trace the fetch-execute (instruction) cycle of the following sequence of MARIE instructions using RTN (similar to Figure 4.14 of your text). Add 200 Store 200 (c) MARIE uses 12-bit address, 16-bit data registers, and 16-bit instructions. What is the maximum memory size in MARIE? Program size? Largest 2’s complement integer? Maximum number of instructions? (d) The following is an incomplete assembler output listing of a MARIE program: 000 5000 | S1 INPUT 001 0003 | JNS R 002 9000 | JUMP S1 003 0000 | R DEC 0 004 200C | STORE Y 005 400B | SUBT X 006 ____ | SKIPCOND 400 007 C003 | JUMPI R 008 | LOAD Y 009 6000 | OUTPUT 00A 7000 | HALT 00B 000A | X Dec 10 00C 0000 | Y Dec 0 | | SYMBOL TABLE -------------------------------------------------- Symbol | Defined | References --------+--------+------------------------------ R | 003 | 001, 007 S1 | 000 | 002 X | | _____ Y | 00C | 004, 008 ------------------------------------------------- (i) What does the first line <Y, 00C, 004, 008> in the symbol table convey to you?

description

Add 200 (b) Suppose initially PC = 100, AC = 1234, M[200] = 234 , trace the fetch-execute (instruction) cycle of the following sequence of MARIE instructions using RTN (similar to Figure 4.14 of your text). (c) MARIE uses 12-bit address, 16-bit data registers, and 16-bit instructions. What is the maximum memory size in MARIE? Program size? Largest 2’s complement integer? Maximum number of instructions? 1. MARIE architecture [28%] Store 200

Transcript of assignment 3 - comp228

Page 1: assignment 3 - comp228

CONCORDIA UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING

COMP 228 Fall 2009 ASSIGNMENT 3

Due: November 3, 2009 ___________________________________________________________________________________

1. MARIE architecture [28%] (a) The registers PC, AC, InREG, OutREG are relevant to the state of a program in the

MARIE ISP. Identify which of these registers are modified when each of the following instructions are executed: (i) Load X, (ii) Subt X, (iii) Input, (iv) Halt, (v) Skipcond, (vi) Jump X, (vii) Jns X, (viii) AddI X.

(b) Suppose initially PC = 100, AC = 1234, M[200] = 234 , trace the fetch-execute (instruction) cycle of the following sequence of MARIE instructions using RTN (similar to Figure 4.14 of your text).

Add 200 Store 200 (c) MARIE uses 12-bit address, 16-bit data registers, and 16-bit instructions.

What is the maximum memory size in MARIE? Program size? Largest 2’s complement integer? Maximum number of instructions?

(d) The following is an incomplete assembler output listing of a MARIE program:

000 5000 | S1 INPUT 001 0003 | JNS R 002 9000 | JUMP S1 003 0000 | R DEC 0 004 200C | STORE Y 005 400B | SUBT X 006 ____ | SKIPCOND 400 007 C003 | JUMPI R 008 | LOAD Y 009 6000 | OUTPUT 00A 7000 | HALT 00B 000A | X Dec 10 00C 0000 | Y Dec 0

| | SYMBOL TABLE -------------------------------------------------- Symbol | Defined | References --------+--------+------------------------------ R | 003 | 001, 007 S1 | 000 | 002 X | | _____

Y | 00C | 004, 008 -------------------------------------------------

(i) What does the first line <Y, 00C, 004, 008> in the symbol table convey to you?

Page 2: assignment 3 - comp228

COMP 228 (System Hardware), Fall 2007 ⎯ Assignment 3 Page 2

(ii) Identify all memory locations containing program data. (iii) Using the instruction set format of MARIE (refer to table 4.2 of your text), fill

in the missing (underlined) entries in the assembler output. (iv) By tracing the execution of the given program (by hand), answer the following

questions: • What will cause the program terminate? • How many times will the instruction at S1 be executed? • What would the program have done upon termination?

2. MARIE programming [27%]

(a) Do problem 17 (page 240) of your text. (b) Do problem 18 (page 240) of your text. (c) Do problem 20 (page 240) of your text.

3. Fetch-Decode-Execute Cycle [15%] Suppose we add a stack-add (SADD) instruction in MARIE where memory location 0 (hex) is reserved to store the stack pointer (address of the top of the stack). When executed, SADD pops the two top elements of the stack and stores their sum in register AC. For example, if M[0] = 200, upon execution, AC = M[200] + M[1FF] and M[0] = M[1FE]. (a) Represent the fetch-decode-exceute cycle of this instruction in RTN. Assume a

register can be incremented/decremented (by 1) without going through the ALU. (b) Write a sequence of MARIE instructions that will do the same function as SADD.

Programming Problem

4. Input/Output in MARIE [30%] Write a MARIE program that repeatedly receives a sequence of decimal digits (one digit at a time), computes their sum and stores it in memory location SUM. The program terminates when a non-digit is received. Assemble and run your program using the MARIE simulator [at http://computerscience.jbpub.com/ecoa/2e/student_resources.cfm]. Debug the program until it works correctly. Submit a correctly working version of your MARIE program along with sample input and output of two simulated runs illustrating its correctness.