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

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 21 October 2016

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

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

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

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 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

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

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

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

MIPS Instruction Reference

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

F. Appendix 6 MIPS Instruction Reference

Assembly Programming

MIPS Reference Guide

Computer Architecture. The Language of the Machine

Week 10: Assembly Programming

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

Reduced Instruction Set Computer (RISC)

The MIPS Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture

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

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

MIPS Instruction Set

Reduced Instruction Set Computer (RISC)

SPIM Instruction Set

TSK3000A - Generic Instructions

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

ECE 15B Computer Organization Spring 2010

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

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

MIPS Instruction Format

CPS311 - COMPUTER ORGANIZATION. A bit of history

Arithmetic for Computers

CS 61c: Great Ideas in Computer Architecture

MIPS%Assembly% E155%

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

Mips Code Examples Peter Rounce

MIPS Assembly Language. Today s Lecture

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

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

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

Examples of branch instructions

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

M2 Instruction Set Architecture

Programming the processor

CSc 256 Midterm (green) Fall 2018

Lec 10: Assembler. Announcements

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

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

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

INSTRUCTION SET COMPARISONS

Concocting an Instruction Set

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

CSc 256 Midterm 2 Spring 2012

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

CS61c MIDTERM EXAM: 3/17/99

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

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

Flow of Control -- Conditional branch instructions

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

CSc 256 Midterm 2 Fall 2011

MIPS Assembly Language

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

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

Number Systems and Their Representations

CMPE324 Computer Architecture Lecture 2

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

ECE 30 Introduction to Computer Engineering

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

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture Experiment

Review: MIPS Organization

CSc 256 Final Fall 2016

Concocting an Instruction Set

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Computer Organization & Design

EE108B Lecture 3. MIPS Assembly Language II

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

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

Review of instruction set architectures

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

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

Project Part A: Single Cycle Processor

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

EE 109 Unit 8 MIPS Instruction Set

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

UCB CS61C : Machine Structures

Computer Architecture I Midterm I

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

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

Chapter 2A Instructions: Language of the Computer

Transcription:

Your Name (please print clearly) 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 Instructions: This is a closed book, closed note exam. Calculators are not permitted. Read each question over before you start to work. If you have a question, raise your hand; do not leave your seat. The meaning of each question should be clear, but if something does not make any sense to you, please ask for clarification. Please work the exam in pencil and do not separate the pages of the exam. If you run out of room, please continue on the back of the previous page. For maximum credit, show your work. Good Luck! 1

Problem 1 (2 parts, 30 points) Storage Allocation, Strings, and Pointers Part A (20 points) Assuming a 32-bit system with 32-bit memory interface and 32-bit addresses, show how the following global variables map into static memory. Assume they are allocated starting at address 6000 and are properly aligned. For each variable, draw a box showing its size and position in the 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]) and struct (e.g., M.part). Assume all alignment restrictions imposed by the hardware are obeyed, and the compiler does not add additional alignment restrictions. Note: int and float are 4 bytes, and double is 8 bytes. 6000 typedef struct{ int x; int y; double *scale; coord; char f[] = Buzz ; char *h = &f[2]; double z = 4.8; char k =! ; coord c = {5, 6, &z; coord *d = &c; int e = c.x; 6004 6008 6012 6016 6020 6024 6028 6032 6036 6040 6044 6048 6052 6056 6060 Part B (10 points) What does the following C fragment print? char *S = twelve+one ; int A[] = {2, 3, 5, 4, 9, 8, 6, 0, 1, 7, 10; int *V = A; do {printf( %c, *(S + *V++)); while(*v!= 10); 2

Problem 2 (2 parts, 30 points) Accessing Arrays and Structs Assuming a 32-bit system, consider the following C fragment: typedef struct{ int R; int G; int B; Pixel; Pixel Image[1024][768] = { ; Pixel *P = Image; int GetG(int i, int j){ int Gij = Image[i][j].G; return (Gij); Part A (10 points) Replace the assignment of Gij with a statement that uses only the identifiers P,i,j, and G to access the value of Image[i][j].G. Do not use the identifier Image in your answer. int Gij = Part B (20 points) Write MIPS code to implement the assignment statement ;//an expression is ok int Gij = Image[i][j].G; from the code above. Assume that the base address of array Image is given in $1, and the values of variables i, and j are given in $2, and $3, respectively. Store the result (Gij) in register $4. (Note: there are more blank lines provided than you need.) Label Instruction Comment 3

Problem 3 (2 parts, 40 points) Consider the following C code fragment: int Bar() { char x = i ; int y = 1; int z; char Name[] = Tom ; int Foo(char [], int, char *); Activation Frames z return(z); = Foo(Name, y, &x); int Foo(char S[], int n, char *c) { int a = 3; if (S[n]) { S[n] = *c; n++; return(n); Part A (18 points) Suppose Bar has been called so that the state of the stack is as shown below. Describe the state of the stack just before Foo deallocates locals and returns to Bar. Fill in the unshaded boxes to show Bar's and Foo's activation frames. Include a symbolic description and the actual value (in decimal) if known. For return addresses, show only the symbolic description; do not include a value. Label the frame pointer and stack pointer. Assume a 32-bit system and maintain word alignment. address description Value 9900 RA of Bar s caller 9896 FP of Bar s caller SP, Bar s FP 9892 RV 9888 9884 9880 9876 9872 9868 9864 9860 9856 9852 9848 9844 9840 FP: 9836 SP: 9832 9828 4

Part B (22 points) Write MIPS code fragments to implement the subroutine Foo by following the steps below. Do not use absolute addresses in your code; instead, access variables relative to the frame pointer. Assume no parameters are present in registers (i.e., access all parameters from Foo s activation frame). You may not need to use all the blank lines provided. label instruction Comment Foo: # set Foo s FP # allocate space for locals # initialize locals # if S[n] == 0 branch to End. Be sure to use load/store byte for values of type char. # otherwise, do Then clauses: S[n] = *c; # n++; # return(n); (store return value, deallocate locals, and return) End: 5

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 + sign_extend(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 + zero_extend(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 & zero_extend(100) or immediate ori $1,$2,100 $1 = $2 zero_extend(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 zero_extend(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 6