CDA 3103 Computer Organization Homework #7 Solution Set

Similar documents
Department of Computer and Mathematical Sciences. Lab 4: Introduction to MARIE

Notes: The Marie Simulator

Computer Organization II CMSC 3833 Lecture 33

CMSC 3833 Lecture 37

The MARIE Architecture

CHAPTER 5 A Closer Look at Instruction Set Architectures

Instruc=on Set Architecture

Problem Points Your Points Total 80

a number of pencil-and-paper(-and-calculator) questions two Intel assembly programming questions

Instruc=on Set Architecture

CHAPTER 5 A Closer Look at Instruction Set Architectures

CSE100 Lecture03 Machines, Instructions, and Programs Introduction to Computer Systems

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. Introduc>on to MARIE

Infix to Postfix Conversion

2.2 THE MARIE Instruction Set Architecture

Instruction content (2/2) Instruction content (1/2) The Instruction Set. Chapter 9. Each instruction must contain 4 basic pieces of information

CHAPTER 5 A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 5. A Closer Look at Instruction Set Architectures

Problem with Scanning an Infix Expression

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Architectures. CHAPTER 5 Instruction Set 5.1 INTRODUCTION 5.2 INSTRUCTION FORMATS

Formal Languages and Automata Theory, SS Project (due Week 14)

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Understand the factors involved in instruction set

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Address Modes effective address

Chapter 5. A Closer Look at Instruction Set Architectures

Problem with Scanning an Infix Expression

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation

CC312: Computer Organization

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

Lecture I: Introduction and Overview

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

Microcontroller Intel [Instruction Set]

CS311 Lecture: The Architecture of a Simple Computer

News from the edge. Image source:

CS 206 Introduction to Computer Science II

MARIE: An Introduction to a Simple Computer

Assessment of Programming Skills of First Year CS Students: Problem Set

CSCE 5610: Computer Architecture

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points]

SOEN228, Winter Revision 1.2 Date: October 25,

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Chapter 4. MARIE: An Introduction to a Simple Computer

Prefix/Infix/Postfix Notation

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Expectations. Why learn Assembly Language? Administrative Issues. Assignments. CSC 3210 Computer Organization and Programming

Computer Organization

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

Arab Open University. Computer Organization and Architecture - T103

STACKS AND QUEUES. Problem Solving with Computers-II

Roll No TCS 402/TIT 402

Parsing Scheme (+ (* 2 3) 1) * 1

Computer Organisation CS303

Lesson 2. Instruction set design

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. MARIE Simulator

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS2383 Programming Assignment 3

MARIE: An Introduction to a Simple Computer

Practical Malware Analysis

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

8051 Overview and Instruction Set

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

Chapter 4. Chapter 4 Objectives. MARIE: An Introduction to a Simple Computer

Computer Architecture Lecture No.4 5-Instruction Set Architecture and Design 5-1 Memory locations and Operations. word

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

The Stack and Queue Types

Project 3: RPN Calculator

Lecture 12 ADTs and Stacks

Darshan Institute of Engineering & Technology for Diploma Studies Unit - 1

2. ADDRESSING METHODS

CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

1/30/2018. Conventions Provide Implicit Information. ECE 220: Computer Systems & Programming. Arithmetic with Trees is Unambiguous

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

CHAPTER 8: Central Processing Unit (CPU)

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Accumulator and memory instructions 1. Loads, stores, and transfers 2. Arithmetic operations 3. Multiply and divide 4. Logical operations 5. Data test

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Lab 7 1 Due Thu., 6 Apr. 2017

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

2010 Summer Answers [OS I]

COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES


Instruction Set Architecture

OSIAC Read OSIAC 5362 posted on the course website

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

SaM. 1. Introduction. 2. Stack Machine

F453 Module 7: Programming Techniques. 7.2: Methods for defining syntax

17. Instruction Sets: Characteristics and Functions

Lecture 4: Instruction Set Architecture

Chapter 4. Chapter 4 Objectives

Transcription:

CDA 3103 Computer Organization Homework #7 Solution Set 1 Problems 1. Write a MARIE assembly program for the following algorithm where the subroutine takes two numbers and returns their product. Your assembly program needs to implement and use such a subroutine. X = 3; Y = 4; X = mult(x, Y); Answer: Assume X and Y are unsigned positive numbers. Two parameters are stored in locations X and Y, and the return value is stored in rtn. Load X Store arg1 Load Y Store arg2 JnS mult / Call the subroutine mult Load rtn Store X Halt mult, Hex 0 Clear Store rtn Loop Load arg2 Skipcond 800 / Check if [AC] > 0 JumpI mult / Return to the main program Subt One Store arg2 Load rtn Add arg1 Store rtn Jump Loop arg1, Hex 0 arg2, Hex 0 rtn, Hex 0 X, Hex 3 Y, Hex 4 ONE, Hex 1 2. Write a MARIE assembly program to compute the quotient of X for two given numbers X Y and Y, and store the result in Z. A quotient is the result of dividing one number by another. For example, if X = 9 and Y = 3, the quotient of X Y is 3. Or if X = 11 and Y = 3, the quotient of X is still 3. Y Answer: Assume X and Y are unsigned positive numbers. Let Z be the memory location storing the quotient, One the memory location storing the constant 1. 1

Loop, Load X Subt Y SkipCond 000 / If X-Y < 0, terminate. Jump Inc End, Halt Inc, Store X / X = X-Y Load Z Add One Store Z / Z = Z+1 Jump Loop X, Dec 11 Y, Dec 3 Z, Dec 0 One, Dec 1 3. Complete the following problems in the exercises section at the end of Chapter 5. 2. Show how the following values would be stored by byte-addressable machines with 32-bit words, using little endian and then big endian format. Assume each value starts at address 10 16. Draw a diagram of memory for each, placing the appropriate values in the correct (and labeled) memory locations. a. 456789A1 16 b. 0000058A 16 c. 14148888 16 Ans. a. Big Endian 45 67 89 A1 Little Endian A1 89 67 45 b. Big Endian 00 00 05 8A Little Endian 8A 05 00 00 c. Big Endian 14 14 88 88 Little Endian 88 88 14 14 9 There are reasons for machine designers to want all instructions to be the same length. Why is this not a good idea on a stack machine? Answer: The only instructions on a stack machine that need to address memory are push and pop. So an operand field is required, which implies the instruction field must be divided into an opcode and an operand. However, the other instructions need not access memory, and can thus consist of only the opcode. To make them all the same length, these instructions would need to be artificially lengthened, which can cause waste of memory for storing program instructions. 2

13 Convert the following expressions from reverse Polish notation to the infix notation. a) 12 8 3 1 + / 12/(8 (3 + 1)) b) 52+2 1+2 (((5 + 2) 2 + 1) 2) c) 357+21 1++ 3 + ((5 + 7) (2 1) + 1) 15 Explain how a stack is used to evaluate the RPN expressions from Exercise 13. a) 12 8 3 1 + / 12, 8, 3 and 1 are pushed onto the stack. The plus operator adds 3 + 1, pops them from the stack, and pushes 4. The minus operator takes 8 4, pops them from the stack, and pushes 4. The divide operator takes 12/4, pops them from the stack, and pushes 3. b) 5 2 + 2 1 + 2 5 and 2 are pushed onto the stack. The plus operator adds 5+2, pops them from the stack, and pushes 7. 2 is pushed, and then the times operator takes 7 X 2, pops them from the stack, and pushes 14. 1 is pushed, and then the plus operator adds 14 + 1, pops them, and pushes 15. 2 is pushed, and then the times operators multiples 15 by 2, pops them, and pushes 30. c) 3 5 7 + 2 1 1 + + 3, 5 and 7 are pushed. The plus operator adds 5 + 7, pops them, and pushes 12. Then 2 and 1 are pushed. The minus operator subtracts 1 from 2, pops them, and pushes 1. The times operator multiplies 12 by 1, pops them, and pushes 12. The 1 is pushed, then the plus operator adds 12 plus 1, pops them, and pushes 13. The plus operator them adds 3 + 13, pops them, and pushes 16. 16 a) Write the following expression in postfix (Reverse Polish) notation. Remember the rules of precedence for arithmetic operators! X = A B + C (D E F ) G + H K The RPN expression is AB CDE F + GHK +/ b) Write a program to evaluate the above arithmetic statement using a stack organized computer with zero-address instructions (so only pop and push can access memory). Push A Push B Subtract Push C Push D Push E Push F Subtract Add Push G Push H 3

Push K Add Div Pop X 22 Suppose we have the instruction Load 500. Given memory and register R1 contain the values below. 0x100 0x600 R1 0x400 0x300 0x200 0x500 0x100 0x600 0x500 0x700 0x800 and assuming R1 is implied in the indexed addressing mode, determine the actual value loaded into the accumulator and fill in the table below: Ans. Mode Immediate Direct Indirect Indexed Value Loaded into AC Mode Value Immediate 500 Direct 100 Indirect 600 Indexed 800 4

4. Use a few sentences to answer each of the following questions. The answers can be found in section 5.1 to 5.4 in the textbook. (a) Explain the di erence between register-to-register, register-to-memory, and memory-tomemory instructions. (b) What does the term endian mean? Why does endian-ness matter? (c) Which of the following programs would be longer: a program written for a zero-address architecture, a program written for a one-address architecture, or a program written for a two address architecture? Why? (d) What are addressing modes? The answers to the above questions can be found in seciton 5.1-5.4. 5