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

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

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

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 Fall problems, 6 pages Exam One 19 September 2012

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 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 Spring problems, 6 pages Exam Three 10 April 2013

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 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

MIPS Instruction Reference

F. Appendix 6 MIPS Instruction Reference

Week 10: 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!

Assembly Programming

MIPS Reference Guide

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

TSK3000A - Generic Instructions

The MIPS Instruction Set Architecture

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

Computer Architecture. MIPS Instruction Set Architecture

MIPS Instruction Set

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

Mips Code Examples Peter Rounce

Arithmetic for Computers

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

Computer Architecture. The Language of the Machine

SPIM Instruction Set

MIPS Instruction Format

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

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

ECE 15B Computer Organization Spring 2010

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

MIPS Assembly Language. Today s Lecture

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

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

CS 61c: Great Ideas in Computer Architecture

CSc 256 Midterm 2 Fall 2011

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

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

CPS311 - COMPUTER ORGANIZATION. A bit of history

CSc 256 Midterm (green) Fall 2018

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

CSc 256 Midterm 2 Spring 2012

M2 Instruction Set Architecture

Examples of branch instructions

Programming the processor

Computer Architecture Experiment

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

Flow of Control -- Conditional branch instructions

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

Number Systems and Their Representations

INSTRUCTION SET COMPARISONS

MIPS Assembly Language

CSc 256 Final Fall 2016

Lec 10: Assembler. Announcements

ECE 30 Introduction to Computer Engineering

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

MIPS%Assembly% E155%

CS3350B Computer Architecture MIPS Instruction Representation

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

Concocting an Instruction Set

CMPE324 Computer Architecture Lecture 2

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Project Part A: Single Cycle Processor

CS61c MIDTERM EXAM: 3/17/99

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

Computer Organization & Design

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

ECE260: Fundamentals of Computer Engineering

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Review: MIPS Organization

Midterm. CS64 Spring Midterm Exam

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

Exam in Computer Engineering

Q1: /14 Q2: /12 Q3: /8 Q4: /8. Total: /42

EE 109 Unit 8 MIPS Instruction Set

ECE260: Fundamentals of Computer Engineering

EE108B Lecture 3. MIPS Assembly Language II

Final Project: MIPS-like Microprocessor

Concocting an Instruction Set

The MIPS R2000 Instruction Set

Digital System Design II

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

Computer Architecture

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

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

CSE 2021: Computer Organization

CS61C : Machine Structures

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

Adventures in Assembly Land

UCB CS61C : Machine Structures

Transcription:

ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam One September 19 th 2013 This is a closed book, closed note texam. Calculators are not permitted. Please work the exam in pencil and do not separate the pages. For maximum credit, show your work. Name: Q1: /30 Q2: /25 Q3: /45 Total: /100 1/6

Question 1 (30 points) Part A: (5 points) write a MIPS code fragment that branches to label Target when register $1 is equal to 0x123456. You are only allowed to use the instructions in the attached sheet. You may use at most 5 instructions. Pay attention to the number of bytes in 0x123456. For maximum credits, include comments. Part B: (10 points) Write a C code fragment that reverses the elements in a 1024- element array A and stores the result in array B, i.e. B[0] gets the value of A[1023], B[1] gets the value of A[1022] B[1023] gets the value of A[0]. You need to use a loop structure, using 1024 lines of assignment will get 0 credit. For maximum credit, declare and initialize variables as needed. int A[1024] = {2, 3, 2, 0, - 4, ; int B[1024]; Part C: (15 points) Write a MIPS code fragment that is equivalent to your code in Part B..data ArrayA:.word 2, 3, 2, 0, - 4, # int A[1024] = {2, 3, 2, 0, - 4, ; ArrayB:.alloc 1024 # int B[1024];.text 2/6

Question 2: (25 points) Part A: (5 points) Given the following multi- dimensional array defined in a C code fragment: int A[4][5]; Suppose the array starts at base address 1000. What is the address of element A[i][j]? Part B: (10 points) Suppose the following variables are declared in a C program. Assuming the variables are allocated in the order that they are declared. The allocation scheme tries not to leave gaps in the memory unless necessary. int A; int B[4]; double C; char D; int E; Suppose A is allocated to address 1000. List where the other variables(arrays) are allocated. For array B, you need to give the range of byte addresses that B spans over. Pay attention to the size of the data types and memory alignment. B: C: D: E: Part C: (10 points) There are four variables A, B, C, and X. All are 32- bit integers. A is at memory address 1000 B is at memory address 2000 C is in register $3 X s address is stored in $4 Write a MIPS code segment that computes X = A + B + C. You can use any register that you deem necessary, but you cannot overwrite $3 or $4. 3/6

Question 3: (45 points) Part A: (5 points) Given the following C code segment: int i, j, sum; sum = 0; for(i=0;i<10;i++) { for(j=0;j<10;j++) { if ( i+j > 10 ) break; sum ++; What is the value of sum when the above code segment completes? Part B: (15 points) Convert the above code segment to MIPS. Pay attention to where the break statement would jump to. Specify your register assignment (to i, j, sum). For maximum credit, include comments. 4/6

Part C (7 points): Given the following C code segment, int a, x, y, z; x = y = z = 0; if ( ( (x = 1) & (y = 2) ) ( z == 1) ) a = 0; else a = 1; 1. What s the value of a after the code executes? (3 points) 2. The compound condition of the if statement has 3 components (on x, y, and z). Which one(s) of the 3 will be evaluated when the above code executes? (4 points) Part D (6 points): Convert the following C code segment from using switch to using if else if else and go to. int x, y; switch (x) { case 0: case 1: y +=1 ; break; case 2: y - =2; case 3: y *= 3; case 4: y /= 4; break; default: y = x; ; y ++; 5/6

Part E (6 points): convert the following C code segment from using while loop to using for loop. int i, sum; i=sum=0; while(1) { if( i > 100 ) break; sum += i; i++; Part F (6 points): Given the following C program, int count; int foo (int x) { int count; x = x + 1; count = 2; return x; int main() { int y; y = count = 0; foo(y); printf( %d %d, y, count); What will main() print? 6/6

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 Last updated 28 October 2005 1