Brock Wilcox CS470 Homework Assignment 2

Similar documents
bits 5..0 the sub-function of opcode 0, 32 for the add instruction

Operations, Operands, and Instructions

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Part 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer

ECE260: Fundamentals of Computer Engineering

Sheet For the following C code: a = b + c; b = a + c; d = a b; Write an equivalent assembly MIPS program. Solution:

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

ECE260: Fundamentals of Computer Engineering

MIPS Coding Continued

CS61C : Machine Structures

CS61C : Machine Structures

Unsigned Binary Integers

Unsigned Binary Integers

CS & IT Conversions. Magnitude 10,000 1,

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

CS61C : Machine Structures

Levels of Programming. Registers

ECE 30 Introduction to Computer Engineering

UCB CS61C : Machine Structures

CSCI 402: Computer Architectures

CSEE 3827: Fundamentals of Computer Systems

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

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

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

Assembler. Lecture 8 CS301

MIPS PROJECT INSTRUCTION SET and FORMAT

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Course Administration

Number System. Introduction. Decimal Numbers

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Lecture 4: Instruction Set Architecture

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Chapter Three. Arithmetic

Lecture 4: MIPS Instruction Set

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

CS 110 Computer Architecture MIPS Instruction Formats

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

CSE 378 Midterm 2/12/10 Sample Solution

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter Two MIPS Arithmetic

Laboratory Exercise 1: Machine Language Instructions

CS3350B Computer Architecture

COMP MIPS instructions 2 Feb. 8, f = g + h i;

ECE 15B Computer Organization Spring 2011

Review. Steps to writing (stateless) circuits: Create a logic function (one per output)

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

2. Define Instruction Set Architecture. What are its two main characteristics? Be precise!

ECE260: Fundamentals of Computer Engineering

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Due Nov. 6 th, 23:59pm No Late Submissions Accepted

MIPS Assembly: Practice Questions for Midterm 1 Saving to and Loading from Memory CS 64: Computer Organization and Design Logic Lecture #6

Instruction Set Architecture

Common Problems on Homework

ECE331: Hardware Organization and Design

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

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

Chapter 3 Arithmetic for Computers

CS3350B Computer Architecture Winter 2015

CS 253. January 14, 2017

CS 430 Computer Architecture. C/Assembler Arithmetic and Memory Access William J. Taffe. David Patterson

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

Chapter 3: Arithmetic for Computers

CS61C : Machine Structures

MIPS History. ISA MIPS Registers

Computer Hardware Engineering

Part 2,Number Systems Questions

ECE/CS 552: Introduction to Computer Architecture ASSIGNMENT #1 Due Date: At the beginning of lecture, September 22 nd, 2010

Instructions: Language of the Computer

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

ANNA Guide. by Dr. Eric Larson Seattle University. Acknowledgments... 2

8*4 + 4 = 36 each int is 4 bytes

Laboratory Exercise 6 Pipelined Processors 0.0

ECE260: Fundamentals of Computer Engineering

EE 3613: Computer Organization Homework #2

Laboratory Single-Cycle MIPS CPU Design (3): 16-bits version One clock cycle per instruction

Homework 1. Problem 1. The following code fragment processes an array and produces two values in registers $v0 and $v1:

Lecture 9: Disassembly

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

MIPS Instruc,ons CS 64: Computer Organiza,on and Design Logic Lecture #8

The MIPS Processor Datapath

Fortunately not. In LC-3, there are a variety of addressing modes that deal with these concerns.

MIPS%Assembly% E155%

MIPS Functions and Instruction Formats

Single cycle MIPS data path without Forwarding, Control, or Hazard Unit

comp 180 Lecture 25 Outline of Lecture The ALU Control Operation & Design The Datapath Control Operation & Design HKUST 1 Computer Science

Number Systems and Their Representations

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CS61C : Machine Structures

Transcription:

Brock Wilcox CS470 Homework Assignment 2 Please complete the following exercises from Chapter 2 of Patterson & Hennessy, Computer Organization & Design: The Hardware/Software Interface, Fourth Edition, Revised Printing, pages 180 ff. 1. Exercise 2.1.1 through 2.1.3 for the following C statement: f = g + (h - i) + 8 Exercise 2.1.1: For the C statements above, what is the corresponding MIPS assembly code? Use a minimal number of MIPS assembly instructions. sub f, h, I add f, g, f addi f, f, 8 Exercise 2.1.2: For the C statements above, how many MIPS assembly instructions are needed to perform the C statement? 3 Exercise 2.1.3: If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f? f = 2 + (3 4) + 8 = 2-1 + 8 = 9 2. Exercise 2.2.4 and 2.2.5 for the following MIPS statements: sub f, $0, h addi g, f, 7 Exercise 2.2.4: For the MIPS assembly instructions above, what is a corresponding C statement? NOTE: I decided that $0 makes more sense g = - h + 7 Exercise 2.2.5: If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f? f = 0 h = -h 3. Exercise 2.4.4 and 2.4.5, for the following MIPS statements: add $s0, $s2, $s3 add $s0, $s0, $s4

subi $s0, $s0, 7 add $s0, $s0, $s1 sub $s4, $s4, $s0 Exercise 2.4.4: For the MIPS assembly instructions above, what is a corresponding C statement? $s4 = $s4 - ($s2 + $s3 + $s4 7 + $s1) (which simplifies to) $s4 = $s4 - $s2 - $s3 - $s4 + 7 - $s1 $s4 = 7 - $s1 - $s2 - $s3 $s4 = 7 - ($s1 + $s2 + $s3) Exercise 2.4.5: For the MIPS assembly instructions above, rewrite the assembly code to minimize the number of MIPS instructions (if possible) needed to carry out the same function. add $s5, $s1, $s2 add $s5, $s5, $s3 addi $s4, $0, 7 sub $s4, $s4, $s5 What would happen if the subi instruction came first? Why? It would end up being useless. Right after that, $s0 would be overwritten with $s2 + $s3, so the subi value placed in $s0 wouldn't affect anything. The end result would be: $s4 = $s4 - ($s2 + $s3 + $s4 + $s1) 4. Exercise 2.7.1 through 2.7.3, using the following binary value: 1111 1111 1111 1111 0101 1010 0101 1010two Exercise 2.7.1: For the patterns above, what base 10 number does the binary number represent, assuming that it is a two's complement integer? -42406 Exercise 2.7.2: For the patterns above, what base 10 number does the binary number represent, assuming that it is an unsigned integer? 4294924890 Exercise 2.7.3: For the patterns above, what hexadecimal number does it represent? 0xFFFF5A5A

5. Exercise 2.7.4 through 2.7.5, using the following decimal value: 65432ten Exercise 2.7.4: For the base 10 numbers above, convert to 2's complement binary. 0b 0000 0000 0000 0000 1111 1111 1001 1000 Exercise 2.7.5: For the base 10 numbers above, convert to 2's complement hexadecimal. 0x0000FF98 6. Exercise 2.8.1 through 2.8.3, only part b The following problems deal with sign extension and overflow. Registers $s0 and $s1 hold the values shown in the table below. You will be asked to perform an MIPS assembly language instruction on these registers and show the result. b. $s0 = 0x00000001sixteen, $s0 = 0xFFFFFFFFsixteen Exercise 2.8.1: add $t0, $s0, $s1 Exercise 2.8.2: sub $t0, $s0, $s1 Exercise 2.8.3: add $t0, $s0, $s1 add $t0, $t0, $s0 7. Exercise 2.10.1 through 2.10.4, only part b In the following problems, the data table contains bits that represent the opcode of an instruction. You will be asked to interpret the bits as MIPS instructions into assembly code and determine what format of MIPS instruction the bits represent. b. 0000 0001 0100 1011 0100 1000 0010 0010two Exercise 2.10.1: For the binary entries above, what instruction do they represent?

000000 = opcode 0 01010 = 10 = $t2 01011 = 11 = $t3 01001 = 9 = $t1 00000 100010 = 34 = sub So we get: sub $t1, $t2, $t3 Exercise 2.10.2: What type (I-type, R-type, J-type) instruction do the binary entries above represent? This is an R-type, operating on registers Exercise 2.10.3: If the binary entries above were data bits, what number would they represent in hexadecimal? 0x014B4822 In the following problems, the data tables contains MIPS instructions. You will be asked to translate the entries into the bits of the opcode and determine the MIPS instruction format. b. sw $t1, 32($t2) Exercise 2.10.4: For the instructions above, show the binary then hexadecimal representation of these instructions. 1010 1101 0100 1001 0000 0000 0010 0000 0xAD490020 8. Exercise 2.11.1 through 2.11.6, only part b In the following problems, the data table contains bits that represent the opcode of an instruction. You will be asked to translate the entries into assembly code and determine what format of MIPS instruction the bits represent. b. 0x02538822 Exercise 2.11.1: What binary number does the above hexadecimal number represent? 0000 0010 0101 0011 1000 1000 0010 0010 Exercise 2.11.2:

What decimal number does the above hexadecimal number represent? 39028770 Exercise 2.11.3: What instruction does the above hexadecimal number represent? 000000 op 0 10010 18 - $s2 10011 19 - $s3 100001 17 - $s1 00000 100010 - sub sub $s1, $s2, $s3 In the following problems, the data table contains the values of various fields of MIPS instructions. You will be asked to determine what the instruction is, and find the MIPS format for that instruction. b. op=0x23, rs=1, rt=2, const=0x4 Exercise 2.11.4: What type (I-type, R-type) instruction do the instructions above represent? I-type Exercise 2.11.5: What is the MIPS assembly instruction described above? lw $v0, 4 I think the rs gets ignored? Exercise 2.11.6: What is the binary representation of the instructions above? 1000 1100 0000 0010 0000 0000 0000 0100