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

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

Computer Architecture

CA Compiler Construction

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

Lecture 3, Performance

Lecture 3, Performance

Date: Summer Stem Section:

Introduction to Hartree-Fock calculations in Spartan

a. Follow the Start-Up Procedure in the laboratory manual. Note the safety rules.

EENG/INFE 212 Stacks

hp calculators HP 35s Using Register Arithmetic Variables and Memory Registers Practice Examples: Calculating Using STO Arithmetic

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

GEPL 4500/5500 Lab 1 Geo-rectifying Imagery Due Wednesday March 2, Geo-rectifying an image:

LAB 2 - ONE DIMENSIONAL MOTION

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

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

Assignment 4: Object creation

Lab 6: Linear Algebra

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

Lab 4: Gauss Gun Conservation of Energy

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

Automata Theory CS S-12 Turing Machine Modifications

Calculating Bond Enthalpies of the Hydrides

Static and Kinetic Friction

Material Covered on the Final

Static and Kinetic Friction

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

ECE 320 Linear Control Systems Winter Lab 1 Time Domain Analysis of a 1DOF Rectilinear System

COVER SHEET: Problem#: Points

Introduction to Computer Tools and Uncertainties

Newton's 2 nd Law. . Your end results should only be interms of m

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

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

Using the Morinus Astrology Program

Evaluation copy. Ground Temperature Measurements. computer OBJECTIVES MATERIALS PRE-LAB QUESTIONS

Physics 1050 Experiment 1. Introduction to Measurement and Uncertainty

Physics 1050 Experiment 6. Moment of Inertia

LABORATORY 1: KINEMATICS written by Melissa J. Wafer '95 June 1993

Determining the Conductivity of Standard Solutions

Physics 1050 Experiment 4. Conservation of Energy and Projectile Motion

Homework 1. Johan Jensen ABSTRACT. 1. Theoretical questions and computations related to digital representation of numbers.

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

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

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 5 Discussion: power(m,n) = m n

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

Lesson 12.7: Sequences and Series

Lab 1 Uniform Motion - Graphing and Analyzing Motion

ECE 220 Laboratory 4 Volt Meter, Comparators, and Timer

ON SITE SYSTEMS Chemical Safety Assistant

EXAMPLES 4/12/2018. The MIPS Pipeline. Hazard Summary. Show the pipeline diagram. Show the pipeline diagram. Pipeline Datapath and Control

PHY 123 Lab 6 - Angular Momentum

Example 1 (Characteristic Equation, Eigenvalue, and Eigenvector)

Instructor s Advance Preparation

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

Vector Analysis: Farm Land Suitability Analysis in Groton, MA

Math Lab 10: Differential Equations and Direction Fields Complete before class Wed. Feb. 28; Due noon Thu. Mar. 1 in class

PHY221 Lab 2 - Experiencing Acceleration: Motion with constant acceleration; Logger Pro fits to displacement-time graphs

Fig. 1 Simple BJT (NPN) current mirror and its test circuit

Electricity. Measuring the force on current-carrying conductors in a homogeneous magnetic field. LEYBOLD Physics Leaflets P

MAT 343 Laboratory 6 The SVD decomposition and Image Compression

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test I. Rebecca A. Simmons & Michael R. Gustafson II

Collisions and conservation laws

Microscale Acid-Base Titration

pka AND MOLAR MASS OF A WEAK ACID

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

PHYSICS LAB FREE FALL. Date: GRADE: PHYSICS DEPARTMENT JAMES MADISON UNIVERSITY

Hooke s Law. Equipment. Introduction and Theory

Project 2: Using linear systems for numerical solution of boundary value problems

Physics 103 Newton s 2 nd Law On Atwood s Machine with Computer Based Data Collection

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

Section Summary. Sequences. Recurrence Relations. Summations. Examples: Geometric Progression, Arithmetic Progression. Example: Fibonacci Sequence

SEM Day 1 Lab Exercises SPIDA 2007 Dave Flora

1 Introduction to Computational Chemistry (Spartan)

Remember that C is a constant and ë and n are variables. This equation now fits the template of a straight line:

Distance From the Sun

TOP MARKET SURVEY INSTRUCTION SHEET. Requirements. Overview

Microsystems Technology Laboratories i-stepperthursday, October 27, 2005 / site map / contact

Looking hard at algebraic identities.

Introduction to Simple Harmonic Motion

Assignment 1: Due Friday Feb 6 at 6pm

Richter Scale and Logarithms

NEW HOLLAND IH AUSTRALIA. Machinery Market Information and Forecasting Portal *** Dealer User Guide Released August 2013 ***

ISIS/Draw "Quick Start"

Relative Photometry with data from the Peter van de Kamp Observatory D. Cohen and E. Jensen (v.1.0 October 19, 2014)

Math 151, Fall 2018 Common Exam 1 Version A

Lab 1: Dynamic Simulation Using Simulink and Matlab

ISSP User Guide CY3207ISSP. Revision C

Bfh Ti Control F Ws 2008/2009 Lab Matlab-1

PHY 221 Lab 5 Diverse Forces, Springs and Friction

Discrete Mathematics -- Chapter 10: Recurrence Relations

Quantification of JEOL XPS Spectra from SpecSurf

The data for this lab comes from McDonald Forest. We will be working with spatial data representing the forest boundary, streams, roads, and stands.

TAMU Spring Math 151, Spring 2019 Common Exam 1 Version A

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 3 Discussion:

Compiling Techniques

DSP First Lab 11: PeZ - The z, n, and ωdomains

Detecting Galactic HI line using 4-m SRT

Linear Motion with Constant Acceleration

EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL

An equation is a statement that states that two expressions are equal. For example:

Transcription:

Lab 5 : Linking Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The main objective of this lab is to experiment with linking two source files together using MARS and the gcc compiler. 2 Pre-requisite For this lab you are expected to be familiar with relocation entries and compiler operation. 1

Computer Architecture and Design, Lab 5 2 3 MIPS Linking 4 Linking files using MARS 1. Type the following program in as a file called lab5-part1.s and load it into MARS. Do not run it yet. 1. data 2. a l i g n 2 3. text 4 main : 5 # p r i n t out prompt 6 l i $v0, 4 # system c a l l code f o r p r i n t i n g s t r i n g = 4 7 la $a0, i n s t r i n g # l o a d address o f s t r i n g to be p r i n t e d i n t o $a0 8 s y s c a l l # c a l l o p e r a t i n g system to perform p r i n t o p e r a t i o n 9 10 # read i n t e g e r i n t o $s0 11 l i $v0, 5 # system c a l l code f o r read i n t e g e r = 5 12 s y s c a l l # c a l l o p e r a t i n g system 13 move $s0, $v0 # v a l u e read from keyboard returned in r e g i s t e r $v0 14 # t r a n s f e r to $s0 15 16 sw $s0, ( $sp ) # push argument f o r Fib on s t a c k 17 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 18 j a l Fib # jump to s u b r o u t i n e 19 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 20 lw $s1, ( $sp ) # and pop r e s u l t from s t a c k 21 22 # p r i n t out prompt 23 l i $v0, 4 # system c a l l code f o r p r i n t i n g s t r i n g = 4 24 la $a0, o u t s t r i n g # l o a d address o f s t r i n g to be p r i n t e d i n t o $a0 25 s y s c a l l # c a l l o p e r a t i n g system 26 27 # p r i n t out r e s u l t ( s t o r e d in $s1 ) 28 l i $v0, 1 # system c a l l code f o r p r i n t i n g i n t e g e r = 1 29 move $a0, $s1 # move i n t e g e r to be p r i n t e d i n t o $a0 : $a0 = $s1 30 s y s c a l l # c a l l o p e r a t i n g system to perform p r i n t 31 j r $ra 2. Provide the expected symbol table for the program. Which of the symbols are external?

Computer Architecture and Design, Lab 5 3 3. Write the relocation table for the program. Hint: list all instructions that use absolute addresses. 4. Now, type in the following new program and save it as lab5-part2.s. 1. data 2 i n s t r i n g :. a s c i i z Input a p o s i t i v e i n t e g e r : \ n\n 3 o u t s t r i n g :. a s c i i z The Fibonacci number i s : \ n\n 4. globl i n s t r i n g # i n s t r i n g i s a g l o b a l l a b e l 5. globl o u t s t r i n g 6. globl Fib 7. a l i g n 2 8. text 9 ##################################################################### 10 # Fibonacci s u b r o u t i n e 11 # i n p u t : i n t e g e r n, on s t a c k 12 # output : Fib (n ), nth Fibonacci number 13 # d e s c r i p t i o n : r e c u r s i v e l y computes Fib (n) = Fib (n 1) + Fib (n 2), 14 # Fib (1) = Fib (2) = 1. 15 # 16 # uses : $t0, $t1 17 ##################################################################### 18 Fib : 19 # procedure p r o l o g u e : 20 sw $ra, ( $sp ) # save r e t u r n address on stack, s i n c e r e c u r s i v e, 21 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 22 sw $fp, ( $sp ) # save p r e v i o u s frame p o i n t e r on s t a c k 23 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 24 add $fp, $sp, 1 2 # s e t frame p o i n t e r to p o i n t at base o f s t a c k frame 25 lw $t0, ( $fp ) # copy argument to $t0 : $t0 = n 26 l i $t1, 2 27 bgt $t0, $t1, d o r e c u r s e # i f argument n >= 2, branch to r e c u r s i v e sequence 28 l i $t0, 1 # e l s e s e t r e s u l t to 1 29 #( base c a s e s n = 1 and n = 2) 30 b e p i l o g u e # branch to end 31 d o r e c u r s e : 32 addi $t0, $t0, 1 # $t0 = n 1 33 sw $t0, ( $sp ) # push argument n 1 on s t a c k 34 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 35 j a l Fib # c a l l Fibonacci with argument n 1 36 # l e a v e r e s u l t on s t a c k f o r now 37 lw $t0, ( $fp ) # re copy argument to $t0 : $t0 = n 38 addi $t0, $t0, 2 # $t0 = n 2 39 sw $t0, ( $sp ) # push argument n 2 on s t a c k

Computer Architecture and Design, Lab 5 4 40 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 41 j a l Fib # c a l l Fibonacci with argument n 2 42 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 43 lw $t0, ( $sp ) # and pop r e s u l t o f Fib (n 2) from s t a c k i n t o $t0 44 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 45 lw $t1, ( $sp ) # and pop r e s u l t o f Fib (n 1) from s t a c k i n t o $t1 46 add $t0, $t0, $t1 # $t0 = Fib (n 2) + Fib (n 1); have r e s u l t 47 e p i l o g u e : # procedure e p i l o g u e : $t0 h o l d s r e s u l t 48 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 49 lw $fp, ( $sp ) # and pop saved frame p o i n t e r i n t o $fp 50 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 51 lw $ra, ( $sp ) # and pop r e t u r n address i n t o $ra 52 addi $sp, $sp, 4 # increment s t a c k p o i n t e r 53 # to pop argument (n) from s t a c k ( d i s c a r d ) 54 sw $t0, ( $sp ) # push r e s u l t onto s t a c k 55 addi $sp, $sp, 4 # and decrement s t a c k p o i n t e r 56 j r $ra # r e t u r n to c a l l e r 57 #################### 58 # end o f Fibonacci # 59 #################### 5. Provide the expected symbol table for the program. Which of the symbols are external? 6. Write the relocation table for the program. Hint: list all instructions that use absolute addresses. 7. Save Lab5-part1.s and lab5-part2.s into the same folder and make sure the option Assemble all files in directory is checked in Settings.

Computer Architecture and Design, Lab 5 5 8. Describe all changes in the text and data segments after loading both files. 9. Give symbol table for the combined program. Make sure the option Show Label Window is checked in Settings. 10. Write the relocation table for combined program. 11. Explain why the implementation given in files Lab5-part1.s and Lab5-part2.s is so inefficient.

Computer Architecture and Design, Lab 5 6 5 Experiments with a real gcc compiler The goal of this section is to experiment with linking two source files together. You will use http://dropzone.tamu.edu/350/ to perform the compilation and linking steps. Alternately, you may use a stand-alone MIPS cross compiler if you have one available. Type the following program and save it as Lab5-part3-1.c. The code contains utility functions to perform IO operations: char prodmessage = The product i s ; void p r i n t i n t ( int a ) asm ( l i $2, 1\n\ t s y s c a l l : / No o u t p u t s / : r ( a ) : %v0 ) ; void p r i n t s t r i n g ( char a ) asm ( l i $2, 4\n\ t s y s c a l l : / No o u t p u t s / : r ( a ) : %v0 ) ; int r e a d i n t ( ) register unsigned long v 0 asm ( $2 ) ; asm ( l i $2, 5\n\ t s y s c a l l : / No o u t p u t s / : / No i n p u t s / : %v0 ) ; return v 0 ; The asm blocks are simply a way to write assembly code within C. These functions simply set up registers for a syscall. If you examine the assembly, you will see that each is only 3 instructions long. Type the code below and save it as Lab5-part3-2.c. The code below reads in two integers from the user, multiplies them together, and then prints the product to the screen.

Computer Architecture and Design, Lab 5 7 extern char prodmessage ; void p r i n t i n t ( int a ) ; void p r i n t s t r i n g ( char a ) ; int r e a d i n t ( ) ; int my mul ( int a, int b ) int i, r e t = 0 ; for ( i =0; i <b ; i ++) r e t = r e t + a ; return r e t ; int main ( void ) p r i n t s t r i n g ( Enter the f i r s t number ) ; int num1 = r e a d i n t ( ) ; p r i n t s t r i n g ( Enter the second number ) ; int num2 = r e a d i n t ( ) ; p r i n t s t r i n g ( prodmessage ) ; p r i n t i n t ( my mul (num1, num2 ) ) ; return 0 ; This is the same program that you designed in lab 4. Compile the two files, and examine their object files. Look at the symbol tables for both files and fill in the following table. Write UND for undefined symbols, and write N/A for symbols not present in a particular file. Also include the section (.data,.text, or another section) for each symbol. Symbol Address in file 1 Address in file 2 Address in linked file Section print int print string read int prodmessage my mul main

Computer Architecture and Design, Lab 5 8 6 PIC Code 1. Open funca code (from the prelab) in MARS. Modify the code by adding few nop instruction in the beginning of the program. List places in code where the native instructions have changed and explain why the change occurred. 2. Take the code you modified in the prelab for funca to be position independent. Save your program as lab5-part4.s, and open it to make sure it is position independent in MARS. Try adding instructions before your code (such as nop) and make sure that program does not change. 7 Deliverables Submit the following: A completed copy of this lab. All source code files created in this lab (with comments).