ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

Similar documents
ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

Q1: /30 Q2: /25 Q3: /45. Total: /100

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

MIPS Instruction Reference

F. Appendix 6 MIPS Instruction Reference

Reduced Instruction Set Computer (RISC)

MIPS Reference Guide

Assembly Programming

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Reduced Instruction Set Computer (RISC)

Computer Architecture. MIPS Instruction Set Architecture

Week 10: Assembly Programming

The MIPS Instruction Set Architecture

MIPS Instruction Set

SPIM Instruction Set

Computer Architecture. The Language of the Machine

ECE Exam I February 19 th, :00 pm 4:25pm

TSK3000A - Generic Instructions

ECE 15B Computer Organization Spring 2010

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

CS 61c: Great Ideas in Computer Architecture

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

MIPS%Assembly% E155%

Mips Code Examples Peter Rounce

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

CPS311 - COMPUTER ORGANIZATION. A bit of history

MIPS Assembly Language. Today s Lecture

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

MIPS Instruction Format

Arithmetic for Computers

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Examples of branch instructions

Programming the processor

Flow of Control -- Conditional branch instructions

M2 Instruction Set Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

MIPS Assembly Language

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CSc 256 Midterm 2 Fall 2011

Concocting an Instruction Set

CSc 256 Midterm 2 Spring 2012

Computer Architecture Experiment

CSc 256 Midterm (green) Fall 2018

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

Lec 10: Assembler. Announcements

MACHINE LANGUAGE. To work with the machine, we need a translator.

INSTRUCTION SET COMPARISONS

Review: MIPS Organization

CS61c MIDTERM EXAM: 3/17/99

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Midterm. Sticker winners: if you got >= 50 / 67

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam Solutions 14 December 2016

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam Solutions 29 April 2015

CS3350B Computer Architecture MIPS Instruction Representation

University of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CSc 256 Final Fall 2016

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

CMPE324 Computer Architecture Lecture 2

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Concocting an Instruction Set

Project Part A: Single Cycle Processor

EE 109 Unit 8 MIPS Instruction Set

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Number Systems and Their Representations

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

ECE 30 Introduction to Computer Engineering

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

We will study the MIPS assembly language as an exemplar of the concept.

Exam in Computer Engineering

Adventures in Assembly Land

Computer Organization & Design

Review of instruction set architectures

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

Compiling Techniques

Transcription:

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate the pages of the exam. For maximum credit, show your work. Good Luck! Your Name (please print) This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give nor receive unauthorized assistance on this exam and to abide by all provisions of the Honor Code. Signed 1 2 3 total 30 30 40 100 1

Problem 1 (2 parts, 30 points) Storage Allocation, Arrays, and Pointers Part A (16 points) Assuming a 64-bit system with 64-bit memory interface and 64-bit addresses, show how the following global variables map into static memory. Assume they are allocated starting at address 4000 and are properly aligned. For each variable, draw a box showing its size and position in the double word memory shown below in which byte addresses increment from left to right. Label the box with the variable name. Label each element of an array (e.g., M[0]). Note: int and float are 32-bits. 4000 int a = 5; int b = 25; int *c = &b; double d = 9.23; double *e = &d; char S[] = Harry ; char *f = &(S[3]); float g = 8.1; double z = 17.25; 4008 4016 4024 4032 4040 4048 4056 4064 Part B (14 points) Assuming a 32-bit system, consider the following declarations: int A[32][16][8] = {...; int *q = A; B.1 Complete the assignment statement below using only q to assign to x the value of A[20][10][2]. int x = *(q + );//an expression is ok B.2 Write the MIPS code implementation of the following assignment statement in the smallest number of instructions. A pointer to the array A is stored in $3 and variables j, i, and y reside in $4, $5, and $6, respectively. Modify only registers $1 and $2. int y = A[0][j][i]; Label Instruction Comment 2

Problem 2 (4 parts, 30 points) Consider the following C code fragment. typedef struct { int age; float height; // in meters float weight; // in kilograms patient; Accessing Structs, Activation Frame Allocation float Calc_and_Print_BMI(int A, float H, float W) { patient Pat; float BMI; BMI = Compute_BMI(&Pat); printf( BMI: %f\n, BMI); return(bmi); /* BMI = weight divided by height squared (units: kg/m 2 ). */ float Compute_BMI(patient *P) { float height_squared = ; // part B float BMI = / height_squared; //part B return(bmi); Part A (6 points) Fill in the blanks in Calc_and_Print_BMI with statements that assign the inputs A, H, and W to the age, height, and weight fields of Pat, respectively. Part B (6 points) Fill in the blanks in Compute_BMI with 1) a statement that squares the height of the patient pointed to by P and 2) a statement that computes the body mass index (BMI) of the patient pointed to by P by dividing the patient's weight by height_squared. Part C (12 points) Assuming a 32-bit system, give the total number of bytes allocated for the activation frame of Calc_and_Print_BMI and the number of bytes for the activation frame of Compute_BMI. Size of activation frame of Calc_and_Print_BMI (in bytes): Size of activation frame of Compute_BMI (in bytes): Part D (6 points) What does the following code fragment print? Code: Answer: char Name[] = "Fred"; char *p = Name; while (*(++p)) printf("%c\n", *p); bytes bytes 3

Problem 3 (1 part, 40 points) Activation Frames The function Bar (below left) calls function Foo after completing code block 1. Write MIPS assembly code that properly calls Foo. Include all instructions between code block 1 and code block 2. Symbolically label all required stack entries and give their values if they are known (below right). int Foo(int Set[], int x, int *y, int z) { <body of Foo> int Bar() { int A[] = {40, 45, 50; int B = 10; int i; <code block 1> Bar s FP 9620 XXX XXX 9616 A[2] 50 9612 A[1] 45 9608 A[0] 40 9604 B 10 SP 9600 i assigned in code block 1 9596 9592 A[i] = Foo(A, A[2], &B, 0); <code block 2> 9588 9584 9580 9576 9572 label instruction comment # Allocate activation frame # Preserve bookkeeping info # Push inputs jal Foo # Call Foo # Restore bookkeeping info # Read return value # Store return value in A[i]: # load i, scale it, and add it # to base address of A to # compute where to store return # value, and store RV there. # Deallocate activation frame 4

MIPS Instruction Set (core) instruction example meaning arithmetic add add $1,$2,$3 $1 = $2 + $3 subtract sub $1,$2,$3 $1 = $2 - $3 add immediate addi $1,$2,100 $1 = $2 + 100 add unsigned addu $1,$2,$3 $1 = $2 + $3 subtract unsigned subu $1,$2,$3 $1 = $2 - $3 add immediate unsigned addiu $1,$2,100 $1 = $2 + 100 set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 set if less than unsigned sltu $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if < immediate unsigned sltui $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 multiply mult $2,$3 Hi, Lo = $2 * $3, 64-bit signed product multiply unsigned multu $2,$3 Hi, Lo = $2 * $3, 64-bit unsigned product divide div $2,$3 Lo = $2 / $3, Hi = $2 mod $3 divide unsigned divu $2,$3 Lo = $2 / $3, Hi = $2 mod $3, unsigned transfer move from Hi mfhi $1 $1 = Hi move from Lo mflo $1 $1 = Lo load upper immediate lui $1,100 $1 = 100 x 2 16 logic and and $1,$2,$3 $1 = $2 & $3 or or $1,$2,$3 $1 = $2 $3 and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $1,$2,100 $1 = $2 100 nor nor $1,$2,$3 $1 = not($2 $3) xor xor $1, $2, $3 $1 = $2 $3 xor immediate xori $1, $2, 255 $1 = $2 255 shift shift left logical sll $1,$2,5 $1 = $2 << 5 (logical) shift left logical variable sllv $1,$2,$3 $1 = $2 << $3 (logical), variable shift amt shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical) shift right logical variable srlv $1,$2,$3 $1 = $2 >> $3 (logical), variable shift amt shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic) shift right arithmetic variable srav $1,$2,$3 $1 = $2 >> $3 (arithmetic), variable shift amt memory load word lw $1, 1000($2) $1 = memory [$2+1000] store word sw $1, 1000($2) memory [$2+1000] = $1 load byte lb $1, 1002($2) $1 = memory[$2+1002] in least sig. byte load byte unsigned lbu $1, 1002($2) $1 = memory[$2+1002] in least sig. byte store byte sb $1, 1002($2) memory[$2+1002] = $1 (byte modified only) branch branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (100*4) branch if not equal bne $1,$2,100 if ($1 $2), PC = PC + 4 + (100*4) jump jump j 10000 PC = 10000*4 jump register jr $31 PC = $31 jump and link jal 10000 $31 = PC + 4; PC = 10000*4 5