Computer Architecture Homework #1 Due: September 7, 2007 (F) (4 PM in ITT 305 mailbox or under my office door, ITT 313)

Similar documents
Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

MIPS Assembly Language Guide

Supplement for MIPS (Section 4.14 of the textbook)

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

MIPS Assembly Programming

Field 6-Bit Op Code rs Field rt Field 16-bit Immediate field

MIPS function continued

Lecture 6 Decision + Shift + I/O

Compiling Techniques

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Chapter 2A Instructions: Language of the Computer

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

Control Instructions

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

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

UCB CS61C : Machine Structures

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

CPSC 330 Computer Organization

Chapter 2. Instructions:

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Topic Notes: MIPS Instruction Set Architecture

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

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

Computer Systems and Networks

Assignment 1: Pipelining Implementation at SPIM Simulator

LAB B Translating Code to Assembly

Chapter 3. Instructions:

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

MIPS Assembly (Functions)

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

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

We can emit stack-machine-style code for expressions via recursion

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

CSc 256 Midterm 1 Fall 2011

Instruction Set Architecture

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

I ve been getting this a lot lately So, what are you teaching this term? Computer Organization. Do you mean, like keeping your computer in place?

CS3350B Computer Architecture MIPS Introduction

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Processor Overview

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

QtSPIM and MARS : MIPS Simulators

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

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

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

Lecture 4: MIPS Instruction Set

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

Instructions: Language of the Computer

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

Going From C to MIPS Assembly. Getting Started

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

CSCE 5610: Computer Architecture

Chapter 2: Instructions:

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

MIPS Memory Access Instructions

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

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

COMPUTER ORGANIZATION AND DESIGN

Processor design - MIPS

Unsigned Binary Integers

Unsigned Binary Integers

CS3350B Computer Architecture

2B 52 AB CA 3E A1 +29 A B C. CS120 Fall 2018 Final Prep and super secret quiz 9

Lecture 4: Instruction Set Architecture

Exceptions and Interrupts

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

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

EE 361 University of Hawaii Fall

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

MIPS Assembly Language. Today s Lecture

CSCI 2321 (Computer Design), Spring 2018 Homework 3

USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470

Solutions for Chapter 2 Exercises

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

MIPS Assembly (FuncDons)

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

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

SPIM & MIPS. Department of Information and Management. Computer Organization and Structure 年 9 月 29 日星期 一

CENG3420 Lecture 03 Review

Code Generation. Lecture 19

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Telematics group University of Göttingen, Germany

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Computer Organization MIPS ISA

Function Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read

CSc 256 Midterm (green) Fall 2018

CDA3100 Midterm Exam, Summer 2013

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Assembler. Lecture 8 CS301

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Transcription:

Computer Architecture Homework #1 Due: September 7, 2007 (F) (4 PM in ITT 305 mailbox or under my office door, ITT 313) Type of Instruction Memory Access (Load and Store) Move Load Address Arithmetic Instruction (reg. operands only) Arithmetic with Immediates (last operand must be an integer) Conditional Branch Unconditional Branch Assembly Language lw $4, Mem sw $4, Mem lw $4, 16($3) sw $4, Mem move $4, $2 li $4, 100 la $5, mem add $4, $2, $3 mul $10, $12, $8 sub $4, $2, $3 addi $4, $2, 100 mul $4, $2, 100 bgt $4, $2, LABEL j LABEL Register Transfer Language Description $4 [Mem] Mem $4 $4 [Mem at address in $3 + 16] [Mem at address in $3 + 16] $4 $4 $2 $4 100 $4 load address of mem $4 $2 + $3 $10 $12 * $8 (32-bit product) $4 $2 - $3 $4 $2 + 100 $4 $2 * 100 (32-bit product) Branch to LABEL if $4 > $2 Always Branch to LABEL sumpos = 0; sumneg = 0; for i = 0 to length-1 do if numbers[i] < 0 then sumneg = sumneg + numbers[i] else sumpos = sumpos + numbers[i] end if end for 1. Write MIPS Assembly Language code for the above algorithm that sums the array's elements..data numbers:.word 2, 3, -1, 10, -5, -6, 3, 5, 1, -5 length:.word 10 sumpos:.word 0 sumneg:.word 0 main:.text.globl main ##### Your code goes here ######## li $v0, 10 syscall # system call for exiting the program 1

General Directions: (This assume you are using PCSpim, but xspim is the labs under Linux too) 1) Log on the Wright lab using your AD-ITS (same account you use for the Library, Union, Dorm, and various hallway computers on campus. If you need your password reset, you must go to ITT 36 for ITS User Support. CNS Support CANNOT reset passwords for student accounts.) 2) Write your assembly language program on paper first! I will not help anyone debug their program without your handwritten program. 3) Type in your program using WordPad and save it on a USB flash memory stick. Remember to use quotes around the file name "hw1.s" (Details below) 4) Debug your MIPS assembly language program. 5) When it is correct, run it to completion and copy to the Window's clipboard a snapshot of the PCSpim window by using the <Alt> and <Print Screen> keys together. 6) Open up new Word document and set its page layout to Landscape by File Page Setup Paper Size and then select Landscape. (Details below) 7) Paste the snapshot of the PCSpim Debugger window into the Word document. Resize the snapshot to the margins and print a copy to turn in. 8) Print a copy of the assembly language program to turn in too. 9) Hand in a copy of your assembly language program and the snapshot of the PCSpim window showing the resulting sorted memory. Entering the Program using WordPad: 1) Start Programs Accessories WordPad 2) Type in the program in a new file 3) File Save As Save in file name: "hw1.s" (USE DOUBLE-QUOTES AROUND FILE NAME) 4) After debugging, print a copy of the program to hand in Running the Program using PCSpim: 1) Start Programs Programming PCSpim 2) Maximize the window by clicking on the 2nd icon in the upper right of the window 3) Load the program by File Open 4) Observe the initial DATA values in memory (hexadecimal) before the program runs: DATA [0x10000000]...[0x10010000] 0x00000000 [0x10010000] 0x00000002 0x00000003 0xffffffff 0x0000000a [0x10010010] 0xfffffffb 0xfffffffa 0x00000003 0x00000005 [0x10010020] 0x00000001 0xfffffffb 0x0000000a 0x00000000 [0x10010030]...[0x10040000] 0x00000000 5) Observe the initial register are all 0 s before the program runs 6) Run the program by Simulator Go, then Click "OK" in the Run Parameters window 7) Observe the resulting DATA values for sumpos and sumneg in memory (hex) after the program runs: DATA [0x10000000]...[0x10010000] 0x00000000 [0x10010000] 0x00000002 0x00000003 0xffffffff 0x0000000a [0x10010010] 0xfffffffb 0xfffffffa 0x00000003 0x00000005 [0x10010020] 0x00000001 0xfffffffb 0x0000000a 0x00000018 [0x10010030] 0xffffffef 0x00000000 0x00000000 0x00000000 [0x10010040]...[0x10040000] 0x00000000 8) Observe the resulting register values after the program runs 9) Copy the PCSpim window to the Window's Clipboard using <Alt><Print Screen> keys 2

Printing the PCSpim window using Word: 1) Start Programs Microsoft Office Microsoft Office Word 2003 2) Type your name at the top of the blank page and hit <enter> 3) Paste in the PCSpim window from the Clipboard by Edit Paste 4) Change to landscape by File Page Setup and then click "Lanscape" button 5) Resize the frame containing the PCSpim picture by clicking on the frame drag the lower-right corner to make the picture bigger 6) Print this picture of the PCSpim window to hand in Downloading PCSpim at Home: To run PCspim on a PC under Microsoft Windows, download the file http://www.cs.wisc.edu/~larus/spim/pcspim.zip, unzip it, and run setup.exe. To run spim or xspim on a Unix or Linux system, copy either the compressed tar file (http://www.cs.wisc.edu/~larus/spim/spim.tar.z) or the gzip'ed tar file ( http://www.cs.wisc.edu/~larus/spim/spim.tar.gz). Both files contains source code and must be compiled on a particular system. 3

Sample program to perform sequential search of an array for a target value. HLL algorithm: int numbers[10] = {25, 5, 40, 50, 30, 8, -1, -5, 20, 9}; int length = 10; int target = 30; // in numbers at index 4 int foundindex = 0; // gets the index of the target if found or -1 if target is not in the array i = 0; while (i < length) and (numbers[i]!= target) do i = i + 1 end while if (i == length) then i = -1 end if foundindex = i Coresponding MIPS assembly language program:.data numbers:.word 25, 5, 40, 50, 30, 8, -1, -5, 20, 9 length:.word 10 target:.word 30 foundindex:.word 0 main:.text.globl main li $8, 0 # Register $8 holds i la $9, numbers # Register $9 holds address of numbers[i] element lw $10, length # Register $10 holds value of length lw $11, target # Register $11 holds value of target while: bge $8, $10, end_while # and lw $12, 0($9) # Register $12 holds value of numbers[i] element value beq $12, $11, end_while addi $8, $8, 1 # increment i addi $9, $9, 4 # move $9 to point to next numbers[i] element # (words in MIPS are 4 bytes) # Alternatively we could have calculated the address of # numbers[i] by the (starting addr. of numbers) + i*4, i.e., # la $9, numbers # mul $13, $8, 4 # add $9, $9, $13 j while end_while: if: bne $8, $10, end_if li $8, -1 end_if: sw $8, foundindex li $v0, 10 syscall # system call for exiting the program 4

2. Compare zero-, one-, two-, three-address, and the load & store machines by writing programs to compute X = (A + B) * (C - D); Y = X / (A * D); for each of the five machines. The instructions available for use are as follows: 3 Address MOVE (X Y) ADD (X Y + Z) SUB (X Y - Z) MUL (X Y * Z) DIV (X Y / Z) 2 Address MOVE (X Y) ADD (X X + Y) SUB (X X - Y) MUL (X X * Y) DIV (X X / Y) 1 Address (Accumulator machine) LOAD M STORE M ADD M SUB M MUL M DIV M Notes: SUB M performs AC = AC - M DIV M performs AC = AC / M 0 Address (Stack machine) PUSH M POP M ADD SUB MUL DIV Notes: SUB performs POP T POP T2 T3 = T2 - T PUSH T3 DIV performs POP T POP T2 T3 = T2 / T PUSH T3 Load/Store Architecture - operands for arithmetic operations must be from/to registers. For example, to perform the high-level statement Z = X - Y we need the code: LOAD R2, X LOAD R3, Y SUB R4, R2, R3 STORE R4, Z 3. Assume 8-bit opcodes, 32-bit absolute addressing, 5-bit register numbers, and 32-bit operands. Compute the number of bits needed in programs from question 1 by completing the following table. 3 Address 2 Address 1 Address 0 Address Load & Store Number of bits needed to store the program Number of bits of data transferred to and from memory Total number of bits read and written while the program executes 5