ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Similar documents
On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Computer Architecture

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

Lecture 3, Performance

Lecture 3, Performance

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

CA Compiler Construction

Administrivia. Course Objectives. Overview. Lecture Notes Week markem/cs333/ 2. Staff. 3. Prerequisites. 4. Grading. 1. Theory and application

Pipelining. Traditional Execution. CS 365 Lecture 12 Prof. Yih Huang. add ld beq CS CS 365 2

Collisions and conservation laws

Lecture 13: Sequential Circuits, FSM

Laboratory Exercise #11 A Simple Digital Combination Lock

Lecture 13: Sequential Circuits, FSM

Compiling Techniques

SuperCELL Data Programmer and ACTiSys IR Programmer User s Guide

COVER SHEET: Problem#: Points

Photometry of a Globular Cluster

A Second Datapath Example YH16

CSE370: Introduction to Digital Design

MENA 9520 FME Modelling Tutorial 5 ( )

ISSP User Guide CY3207ISSP. Revision C

Automata Theory CS S-12 Turing Machine Modifications

Senior astrophysics Lab 2: Evolution of a 1 M star

Digital Systems EEE4084F. [30 marks]

Laboratory Exercise #8 Introduction to Sequential Logic

Working with Digital Elevation Models in ArcGIS 8.3

Foundations of Computation

Mark Redekopp, All rights reserved. Lecture 1 Slides. Intro Number Systems Logic Functions

Astronomy 101 Lab: Stellarium Tutorial

Project Two RISC Processor Implementation ECE 485

NINE CHOICE SERIAL REACTION TIME TASK

ww.padasalai.net

Department of Electrical and Computer Engineering The University of Texas at Austin

ST-Links. SpatialKit. Version 3.0.x. For ArcMap. ArcMap Extension for Directly Connecting to Spatial Databases. ST-Links Corporation.

Computer Engineering Department. CC 311- Computer Architecture. Chapter 4. The Processor: Datapath and Control. Single Cycle

BCMB/CHEM 8190 Lab Exercise Using Maple for NMR Data Processing and Pulse Sequence Design March 2012

Date: Summer Stem Section:

Please click the link below to view the YouTube video offering guidance to purchasers:

CPSC 3300 Spring 2017 Exam 2

HOW TO USE MIKANA. 1. Decompress the zip file MATLAB.zip. This will create the directory MIKANA.

CSE Computer Architecture I

CSCE 155N Fall Homework Assignment 2: Stress-Strain Curve. Assigned: September 11, 2012 Due: October 02, 2012

Building a Computer. Quiz #2 on 10/31, open book and notes. (This is the last lecture covered) I wonder where this goes? L16- Building a Computer 1

Cosmic Ray Detector Software

ECE3510 Lab #5 PID Control

- Why aren t there more quantum algorithms? - Quantum Programming Languages. By : Amanda Cieslak and Ahmana Tarin

Double Inverted Pendulum (DBIP)

Tutorial 11. Use of User-Defined Scalars and User-Defined Memories for Modeling Ohmic Heating

Results Combination Using Restart

ON SITE SYSTEMS Chemical Safety Assistant

Assembly Programming through Arduino

A crash course in Digital Logic

ECE290 Fall 2012 Lecture 22. Dr. Zbigniew Kalbarczyk

EXPERIMENT 7: ANGULAR KINEMATICS AND TORQUE (V_3)

Microprocessor Power Analysis by Labeled Simulation

SOLUTION. Homework 1. Part(a) Due: 15 Mar, 2018, 11:55pm

Material Covered on the Final

Homework 1. Part(a) Due: 15 Mar, 2018, 11:55pm

v Prerequisite Tutorials GSSHA WMS Basics Watershed Delineation using DEMs and 2D Grid Generation Time minutes

System Data Bus (8-bit) Data Buffer. Internal Data Bus (8-bit) 8-bit register (R) 3-bit address 16-bit register pair (P) 2-bit address

Static and Kinetic Friction

How Do I Create a Hubble Diagram to show the expanding universe?

Lab Partner(s) TA Initials (on completion) EXPERIMENT 7: ANGULAR KINEMATICS AND TORQUE

SEM Day 1 Lab Exercises SPIDA 2007 Dave Flora

Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by:

Using the Stock Hydrology Tools in ArcGIS

Conformational Analysis of n-butane

SOFTWARE USER MANUAL. Weather Capture Advance WS1640 WM9280

Your work from these three exercises will be due Thursday, March 2 at class time.

Virtual Beach Making Nowcast Predictions

Simulating Future Climate Change Using A Global Climate Model

CMSC 313 Lecture 16 Announcement: no office hours today. Good-bye Assembly Language Programming Overview of second half on Digital Logic DigSim Demo

L07-L09 recap: Fundamental lesson(s)!

McIDAS-V Tutorial Displaying Point Observations from ADDE Datasets updated July 2016 (software version 1.6)

Programming Language Concepts, CS2104 Lecture 3

BASIC TECHNOLOGY Pre K starts and shuts down computer, monitor, and printer E E D D P P P P P P P P P P

LABORATORY MANUAL MICROPROCESSOR AND MICROCONTROLLER

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

A Brief Introduction To. GRTensor. On MAPLE Platform. A write-up for the presentation delivered on the same topic as a part of the course PHYS 601

In-System Serial Programming (ISSP) Guide

C2A for Pulsar2 how to control your telescope from C2A

Creating Empirical Calibrations

Big-O Notation and Complexity Analysis

Account Setup. STEP 1: Create Enhanced View Account

Binary addition example worked out

Chem Page IX - 1 LAB MANUAL Differential Scanning Calorimetry 09_dsc131.docx EXPERIMENT IX

Cantera / Stancan Primer

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

ECE 3401 Lecture 23. Pipeline Design. State Table for 2-Cycle Instructions. Control Unit. ISA: Instruction Specifications (for reference)

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00

Computer Architecture ELEC2401 & ELEC3441

Spatial Analysis using Vector GIS THE GOAL: PREPARATION:

Experiment A11 Chaotic Double Pendulum Procedure

Quantum Computing Virtual Machine. Author: Alexandru Gheorghiu Scientific advisor: PhD. Lorina Negreanu

QUANTUM CHEMISTRY WITH GAUSSIAN : A VERY BRIEF INTRODUCTION (PART 2)

In-System Serial Programming (ISSP) Guide

Laboratory 3 Measuring Capacitor Discharge with the MicroBLIP

At the end of the exam you must copy that folder onto a USB stick. Also, you must your files to the instructor.

1 Classical Propositional Logic [20 points]

Transcription:

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University Prof. Mi Lu TA: Ehsan Rohani Laboratory Exercise #4 MIPS Assembly and Simulation Objective The objective of lab this week is to familiarize you with the MIPS Instruction Set Architecture (ISA). In order to build a machine, we must understand how to use it. In lab, you will assemble and simulate a few simple programs written in assembly language. You will use the simulator to see the flow of data through the MIPS machine as it executes a program. Additionally, you will have the opportunity to improve upon provided code and will use the simulator to view your improvement. Background The Instruction Set Architecture (ISA) sits at the boundary between hardware and software and provides a well defined set of instructions that both the programmer (or compiler) and the processor understand. Software development using these primitive instructions is referred to as assembly language programming. Today, most software development is performed with a higher level language such as C or C++ and compiled down to assembly code; however, there is still some merit in programming at such a low level. For this class, it is a necessary step, required to strengthen your understanding of the processor itself. For the embedded developer, it may be necessary to write a kernel or a small portion of an algorithm in assembly code for an Operating System (OS) port or efficiency reasons, while for the general programmer, an understanding of what the C or C++ code being written will eventually be translated to will aide in the developer s ability to create efficient programs from the start. For assembly code simulation, we will use the MIPS Assembler and Runtime Simulator (MARS) from Missouri State University. 1

2 Laboratory Exercise #4 MARS provides an intuitive Integrated Development Environment (IDE) for assemble language programming in a portable (written in Java platform). For your use at home, MARS may be downloaded for free at http://courses.missouristate.edu/kenvollmar/mars/ Procedure 1. Introduction to MARS and a very simple assembly language program. (a) Start MARS by first opening up a terminal window, then invoking the following command: >java -jar /homes/grad/atarghe1/ecen651/mars_4_1.jar (b) From within the IDE, select File New to create a new source file. Note the.asm file extension. (c) Enter the following code into the editor within MARS:. t e x t # t e x t s e c t i o n. g l o b l main # c a l l main a d d i $t1, $0, 8 # l o a d immediate v a l u e ( 8 ) i n t o $ t 1 a d d i $t2, $0, 9 # l o a d immediate v a l u e ( 9 ) i n t o $ t 2 add $t3, $t1, $ t 2 # add two numbers i n t o $ t 3 j r $ r a # r e t u r n from main ; r e t u r n a d d r e s s s t o r e d i n $ r a (d) Please note the following MIPS assembly language syntax rules: Text that follows a sharp sign (#) is a comment. A line that starts with a period (.) is an assembler directive. Assembler directives are a way of instructing the assembler how to translate a program but do not produce machine instructions. For example at line 6 in the code below,.globl main defines main as a global variable. Text followed by a colon (:) defines a label. It is similar to defining variables in any highlevel language, for example int var in C-language. (e) Save the file as prog1.asm in your lab4 directory and click on Run Assemble. (f) Select the Execute tab in MARS and record the following things in your lab write-up: The original source with pseudo instructions The actual MIPS instructions they translate to The machine code the MIPS instructions translate to The address where each machine instruction is located 2 ECEN 651

Laboratory Exercise #4 3 (g) Explain what the simple program does. (h) Now select Run Step to single step through the program. Examine the state of the machine provided in the Registers window on the right as you single step through your program. Take note of the PC register and the registers referenced in the program. Record changes you see in the temporary registers (i.e. $t0 through $t9). 2. Assemble and simulate a slightly more complex program with system calls to interact with the user. (a) Create a new file called prog2.asm and type in the following program:. d a t a msg1 :. a s c i i z P l e a s e e n t e r an i n t e g e r number : msg2 :. a s c i i z \ t F i r s t r e s u l t : msg3 :. a s c i i z \ tsecond r e s u l t :. t e x t. g l o b l main # I n s i d e main t h e r e a r e some c a l l s ( ) which w i l l change t h e # v a l u e i n r e g i s t e r $ r a which i n i t i a l l y c o n t a i n s t h e r e t u r n # a d d r e s s from main. This needs t o be saved. addu $s0, $ra, $0 # save $31 i n $16 l i $v0, 4 # system c a l l f o r p r i n t s t r l a $a0, msg1 # a d d r e s s of s t r i n g t o p r i n t # now g e t an i n t e g e r from t h e u s e r l i $v0, 5 # system c a l l f o r r e a d i n t # t h e i n t e g e r p l a c e d i n $v0 # do some c o m p u t a t i o n h e r e with t h e i n t e g e r addu $t0, $v0, $0 # move t h e number i n $v0 t o $ t 0 s l l $t1, $t0, 2 # c o m p u t a t i o n 1, r e s u l t i s i n $ t 1 s r l $t2, $t0, 2 # c o m p u t a t i o n 2, r e s u l t i s i n $ t 2 # p r i n t t h e f i r s t r e s u l t l i $v0, 4 # system c a l l f o r p r i n t s t r l a $a0, msg2 # a d d r e s s of s t r i n g t o p r i n t l i $v0, 1 # system c a l l f o r p r i n t i n t addu $a0, $t1, $0 # move number t o p r i n t i n $a0 ECEN 651 3

4 Laboratory Exercise #4 # p r i n t t h e second r e s u l t l i $v0, 4 # system c a l l f o r p r i n t s t r l a $a0, msg3 # a d d r e s s of s t r i n g t o p r i n t l i $v0, 1 # system c a l l f o r p r i n t i n t addu $a0, $t2, $0 # move number t o p r i n t i n $a0 # r e s t o r e now t h e r e t u r n a d d r e s s i n $ r a and r e t u r n from main addu $ra, $0, $s0 # r e t u r n a d d r e s s back i n $31 j r $ r a # r e t u r n from main $ (b) Using the MIPS reference card listed on the lab website as an aide, examine the code and explain what exactly it is doing. Hint: Look specifically at the SYSCALLS section of the reference card. (c) Verify the operation of the above code in MARS by assembling the code and then selecting Run Go to execute the code to completion without single stepping. Copy the program output displayed in the Run IO window into your lab write-up. (d) Take some time to examine the Text Segment and Data Segments under the Execute tab in MARS. What exactly do these sections contain? (e) Reset the program by selecting Run Reset and now single step through it examining the register contents as you go. Record changes you see in the temporary registers (i.e. $t0 through $t9). (f) Describe in your lab write-up the operation of the PC register. 3. Assemble a program which interacts with memory (i.e. contains loads and stores). (a) Create a new file called prog3.asm and type the following code into that file:. d a t a msg1 :. a s c i i z A 17 b y t e message msg2 :. a s c i i z Another message of 27 b y t e s num1 :. b y t e 45 num2 :. h a l f 654 num3 :. word 0 x c a f e b a b e num4 :. word 0 x f e e d f a c e. t e x t. g l o b l main 4 ECEN 651

Laboratory Exercise #4 5 addu $s0, $ra, $0 # save t h e r e t u r n a d d r e s s l i $v0, 4 # system c a l l f o r p r i n t s t r l a $a0, msg1 # a d d r e s s of s t r i n g t o p r i n t l a $a0, msg2 # a d d r e s s of s t r i n g t o p r i n t l b $t0, num1 # l o a d num1 i n t o $ t 0 l h $t1, num2 # l o a d num2 i n t o $ t 1 lw $t2, num3 # l o a d num3 i n t o $ t 2 lw $t3, num4 # l o a d num4 i n t o $ t 3 addu $ra, $s0, $0 # r e s t o r e t h e r e t u r n a d d r e s s j r $ r a # r e t u r n from main (b) Examine the contents of the Data Segment within MARS. Select the ASCII check box at the bottom of the window and record the start address for the two strings in the program (i.e. msg1 and msg2. (c) Assemble and run the program, single stepping through the instructions. Note the contents of the registers as the code executes. Copy the program output displayed in the Run IO window into your lab write-up. (d) Now type in prog4.asm listed below:. d a t a h e x t a b l e :. a s c i i 0123456789 a b c d e f msg1 :. a s c i i z Your number i n Hex i s :. t e x t. g l o b l main addu $s0, $0, $ r a # save t h e r e t u r n a d d r e s s l i $v0, 5 # f o r r e a d i n t add $s1, $v0, $0 l i $v0, 4 # f o r p r i n t s t r l a $a0, msg1 l a $a1, h e x t a b l e s r l $t0, $s1, 4 # g e t upper 4 b i t s add $a2, $a1, $ t 0 # g e t a d d r e s s i n h e x t a b l e l b $a0, 0( $a2 ) # g e t c h a r a c t e r l i $v0, 11 # f o r p r i n t c h a r ECEN 651 5

6 Laboratory Exercise #4 a n d i $t0, $s1, 0 xf # g e t lower 4 b i t s add $a2, $a1, $ t 0 # g e t a d d r e s s i n h e x t a b l e l b $a0, 0( $a2 ) # g e t c h a r a c t e r l i $v0, 11 # f o r p r i n t s t r addu $ra, $s0, $0 # r e s t o r e r e t u r n a d d r e s s j r $ r a # r e t u r n from main (e) Assemble and run the provided program. In the IO window, enter a number between 1 and 255. (f) Explain the operation of the program in your lab write-up. 4. Assemble and simulate a program with control instruction such as beq and jal. (a) Assemble prog5.asm provided below:. d a t a msg1 :. a s c i i z E n t e r t h e f i r s t number \n msg2 :. a s c i i z E n t e r t h e second number \n msg :. a s c i i z The p r o d u c t i s. t e x t. g l o b l main. g l o b l my mul a d d i $sp, $sp, 8 #make room f o r $ r a and $fp on t h e s t a c k sw $ra, 4( $sp ) # push $ r a sw $fp, 0( $sp ) # push $fp l a $a0, msg1 # l o a d a d d r e s s of msg1 i n t o $a0 l i $v0, 4 # p r i n t msg1 l i $v0, 5 # r e a d i n t add $t0, $v0, $0 # p u t i n $ t 0 l a $a0, msg2 # l o a d a d d r e s s of msg2 i n t o $a0 l i $v0, 4 # p r i n t msg2 l i $v0, 5 6 ECEN 651

Laboratory Exercise #4 7 # r e a d i n t add $a1, $v0, $0 # p u t i n $a1 add $a0, $t0, $0 # p u t f i r s t number i n $a0 add $fp, $sp, $0 # s e t fp t o t o p of s t a c k p r i o r # t o f u n c t i o n c a l l j a l my mul #do mul, r e s u l t i s i n $v0 add $t0, $v0, $0 # save t h e r e s u l t i n $ t 0 l a $a0, msg l i $v0, 4 # p r i n t msg add $a0, $t0, $0 # p u t c o m p u t a t i o n r e s u l t i n $a0 l i $v0, 1 # p r i n t r e s u l t number lw $fp, 0( $sp ) # r e s t o r e ( pop ) $fp lw $ra, 4( $sp ) # r e s t o r e ( pop ) $ r a a d d i $sp, $sp, 8 # a d j u s t $sp j r $ r a # r e t u r n my mul : # m u l t i p l y $a0 with $a1 # does n o t h a n d l e n e g a t i v e $a1! # Note : This i s an i n e f f i c i e n t way t o m u l t i p y! a d d i $sp, $sp, 4 #make room f o r $s0 on t h e s t a c k sw $s0, 0( $sp ) # push $s0 add $s0, $a1, $0 # s e t $s0 e q u a l t o $a1 add $v0, $0, $0 # s e t $v0 t o 0 m u l t l o o p : beq $s0, $0, m u l t e o l add $v0, $v0, $a0 a d d i $s0, $s0, 1 j m u l t l o o p m u l t e o l : lw $s0, 0( $sp ) #pop $s0 j r $ r a (b) Set the Run speed bar at the top of MARS to about 2 inst/sec and then run the program. (c) What does the run speed bar do? ECEN 651 7

8 Laboratory Exercise #4 (d) Watch the program as it executes and summarize its operation in your lab write-up. (e) The method used to perform multiplication is very inefficient. Rewrite the multiplication routine to perform multiplication with the Shift-and-Add method. Compare and contrast the two methods (i.e. the one provided with the one you write) of multiplication in your lab write-up. 1 Deliverables 1. Submit a lab report that captures your efforts in lab. 2. Include all assembly source files with the comments provided. Note: Code submitted without adequate comments will not be graded! 3. Be sure to include all material requested in lab. 4. Answer the following review questions: (a) Explain how the target address in a branch instruction is calculated. How about for a jump instruction? What is the different between jump and jump and link (i.e. jal)? (b) List the registers that must be preserved during the execution of a procedure. Which registers do not have to be preserved? (c) What are the steps necessary to call a procedure? Be sure to include the interaction with the stack and frame pointers. Use prog5.asm as a reference. 8 ECEN 651