Computer Organization - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Computer Organization

Description:

Floating Point has no pre-defined rules so you need to do it yourself. ... This will be used as part of Projects 7 - 9. A Debugging Aid. ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 24
Provided by: jb20
Category:

less

Transcript and Presenter's Notes

Title: Computer Organization


1
Computer Organization
Project 7 - 9 Prof. Jerry Breecher CSCI
140 Spring 2005
2
Using Software Engineering
  • This is a multi-week Project to develop skills in
    Software Engineering.
  • The schedule looks like this
  • Project 6 Learn how to decompose a problem.
  • Apply decomposition to the cafeteria problem and
    to the Binomial Expansion
  • Project 7 Write a program to solve the Binomial
    Expansion in your favorite high level language.
    Learn how to do floating point instructions.
  • Working Binomial Expansion Program (in HLL) is
    due next week in lab.
  • Include a test plan. Hand in Code Get checked
    off that it works.
  • Project 8 Structure your program to match your
    decomposition. You are essentially writing
    pseudo-code for the program.
  • No explicit assignment due for this week.
  • Project 9 Fill in the pseudo-code and produce a
    successful program.
  • Working Binomial Expansion Program (in MIPS) Due
    next week by lab time.
  • Hand in Code Get checked off that it works.
  • This sequence is worth four weeks of Project
    Credit.

3
Project 6
  • Practice Decomposition
  • Continue the decomposition of the cafeteria
    problem.
  • Decompose the Binomial Expansion problem. Notice
    that this problem has a number of features
  • Its iterative there are multiple terms so that
    you need some kind of loop to handle each term.
  • It has numerous functions that are performed.
    These include factorial, taking-a-power,
    combination of terms, etc.

4
Project 7
  • Task 1
  • Write a test plan. You say, How can this be
    difficult? Theres only one input? But beware
    of tricky numbers. Do you have a test case that
    will make the looping go on forever? Are there
    positive and negative numbers, etc. Think evil
    because I will try these test cases on YOUR code!
  • Task 2
  • Write a program to do a Binomial Expansion using
    your favorite high level language.
  • The program you write should be tailored so that
    it has the same components that youve specified
    in your decomposition in Project 6. Some of
    these sections may be only 1 line long, but
    thats OK. By the time you write this code in
    MIPS, youll find one line of HLL 20 lines of
    MIPS.

5
Project 7
  • Task 3
  • Understand and use the sample program that will
    introduce you to Floating Point code. This code
    is NOT obvious it has some subtle tricks in it.
  • Read the code.
  • Get into SPIM and debug it. Look at what is in
    the registers.
  • Make sure you understand it.
  • Make sure you understand the difference between
    Wide and Floating Point Registers, and Integer
    and Double data.
  • The sample program can be found at
  • http//babbage.clarku.edu/jbreecher/comp_org/labs
    /Project07-Sample.s
  • The code for this is reproduced later in this
    document.

6
Project 8
  • Structure your program to match your
    decomposition. You are essentially writing
    pseudocode for the program. There is no actual
    CODING just setup described here.
  • Heres how you go about doing this.
  • Task 1
  • At the beginning of your program, define all the
    variables you are going to use.
  • For Wide registers, you had a definition of s
    and t variables they were used in different
    ways its a question of who saves the
    variables.
  • Floating Point has no pre-defined rules so you
    need to do it yourself. Make up rules for these
    registers that you can live with.
  • Setting up registers to be used as the sum of
    terms, or the value for this term, etc., will
    make your life much easier.
  • .

7
Project 8
  • Task 2
  • For each of the pieces of your Project 6
    decomposition, produce a division of your
    program. There are two types of division that
    work well here
  • A subroutine is a natural division. We already
    know how to do this.
  • A sub-section of your code delimited by a big
    comment section.
  • Whether you use subroutines or sub-sections,
    heres what MUST be in the comments for each of
    these divisions
  • The comment section must describe
  • What variables are input into that division
    (pre-condition).
  • What variables are output from that division
    (post-condition).
  • What variables are used/modified in that
    division.
  • For a set of sample input, what outputs are
    expected these are called test points.

8
Project 9
  • Start writing the code. This should be easy
    since you
  • know what values to expect into and out of each
    of the divisions.
  • You know the algorithm.
  • You know what variables to try in your testing.

9
EXAMPLES
  • In this section, there is an Example, a Debugging
    Aid, and a Problem Definition.
  • An Example of how to program in MIPS Floating
    Point. This will be used as part of Projects 7 -
    9.
  • A Debugging Aid. When you have a decomposition
    in mind, you should KNOW the output from each of
    the pieces. If you dont KNOW, youll never
    debug your code.
  • The definition of the Binomial Expansion problem
    as given in Project 6.

10
Project 7 - The Sample Program

  • PROJECT7-EXAMPLE.S
  • Here are shown a number of interesting
    programming mechanisms that
  • will help you in dealing with floating point
    data and operations.
  • LANGUAGE USED HERE - I hope to be consistent
  • Wide Register
  • - these are the 32 bit registers we've been
    using.
  • Floating Point (FP) Register
  • - The 32 registers numbered f0 - f31. For
    64 bit data, they can
  • be grouped together. They are numbered f0,
    f2, f4, ... f30.
  • Integer Data
  • - This is 32 bit data (that we've been using
    all semester) that
  • represents integers from 2,147,483,647 to
    -2,148,483,648
  • Double Data

11
The Sample Program
  • .text
  • .globl main
  • main
  • addi sp, sp, -4
  • sw ra, 0(sp)
  • Moving Data between Wide and FP
    Registers
  • Note we're just moving bit patterns - there's
    no type representation
  • mtc1 is bizarro - the data movement is
    backwards - be careful!!
  • addi t0, zero, 22 Load a
    number into Wide
  • mtc1 t0, 0 Move
    FROM t0 TO register 0
  • in
    co-processor.
  • mfc1 t1, 0 Move
    FROM 0 TO t1
  • Moving Data between Wide Registers
    and Memory
  • This is what we've been doing all semester -
    nothing new here.
  • lw t2, integer Get
    data into register

12
The Sample Program
  • Moving Data between FP Registers and
    Memory
  • These instructions move 64 bits of data - all
    in one instruction.
  • l.d f2, double_value Move
    64 bits from Mem. to Reg.
  • s.d f2, double_value2 Move
    64 bits from Reg. to Mem.
  • Moving Data between FP Registers and
    Memory
  • These instructions move 32 bits of data. To
    get the equivalent of
  • the instruction l.d f6, double value do
    these operations twice.
  • lwc1 f4, single_value Move
    32 bits from Mem. to Reg.
  • swc1 f4, single_value2 Move
    32 bits from Reg. to Mem.
  • lwc1 f6, double_value Move
    the first 32 bits
  • lwc1 f7, double_value4 Move
    the second 32 bits
  • swc1 f6, double_value3 Move
    the first 32 bits
  • swc1 f7, double_value34 Move
    the second 32 bits

13
The Sample Program
  • Converting Types Between Double and
    Wide
  • An entirely separate action is to convert
    types beween Integer and
  • Double. Watch this magic and make sure you
    understand it.
  • lwc1 f8, integer Move
    integer type from Mem to FP
  • cvt.d.w f10, f8
    Convert Integer to Double
  • cvt.w.d f12, f10
    Convert Double back to Integer
  • swc1 f12, integer3 Put it
    back into memory

14
The Sample Program
  • Here's an example of how to use all
    this.
  • We're going to calculate the circumference of
    a circle.
  • 1. Get a radius from the user.
  • 2. Multiply the radius by 2 pi
  • 3. Print it out.
  • Variables are
  • f2 - radius
  • f4 - pi
  • f6 - circumference
  • f20 - f30 - temporaries
  • If we input a value of 3 for the radius, we
    should get a circumference
  • of 18.84954.

15
The Sample Program
  • la a0, prompt Tell
    the user
  • li v0, 4
  • syscall
  • li v0, 7 Read
    in a double
  • syscall
  • mov.d f2, f0 Store
    the radius
  • li t0, 2 Get an
    integer 2
  • mtc1 t0, 20 Move
    integer to F.P. register
  • cvt.d.w f20, f20
    Convert integer to double
  • l.d f4, pi Get
    double from memory
  • mul.d f6, f2, f4
  • mul.d f6, f6, f20
  • la a0, answer Print
    out text
  • li v0, 4
  • syscall
  • li v0, 3
    Prepare to print result
  • mov.d f12, f6 We
    print what's in f12
  • syscall
  • la a0, nl Print
    out text

16
The Sample Program
  • .data
  • double_value
  • pi
  • .double 3.14159
  • double_value2
  • .space 8
  • double_value3
  • .space 8
  • single_value
  • .float 3.14
  • single_value2
  • .space 4
  • integer
  • .word 17
  • integer2
  • .space 4
  • integer3
  • .space 4
  • prompt

17
Sample - Debugging
  • Debugging is a skill that is difficult to attain.
    One of the chief difficulties is knowing what to
    expect. As you write your code for Project 7,
    consider taking a test case where you know the
    answer.

Numerator
Term 0
Term 3
Denominator
Coefficient 4
So the equation is made up of multiple terms.
Each term has a sign, a coefficient, and a
power-of-X. Each coefficient has a numerator and
a denominator. Each numerator has multiple parts.
18
Sample - Debugging
  • Lets suppose you want to find (1 0.5)4. Given
    that problem, then X 0.5. What are the values
    of the various terms in your calculation?

X 0.5, n 4
Fill in the rest of this chart!
19
Sample - Debugging
  • Lets suppose you want to find (1 - 0.5)3. Given
    that problem, then X -0.5. What are the values
    of the various terms in your calculation?

X -0.5, n 3
Fill in the rest of this chart!
20
The Problem
  • Heres a description of the problem you are to
    solve. You will do this via the method described
    on the previous pages.
  • Finding a Binomial Expansion the value of (1
    x)n
  • Computers, of course, can be asked to solve many
    functions. In C a problem could be solved by
    using the equation
  • double pow( double x, double y ) // The
    prototype
  • y pow( ( 1 x ), n )
  • In this example, theres a C runtime library
    routine called pow that is linked in when the
    executable is being created. This library
    routine knows how to do the power function.

21
The Problem
  • So, how does C solve this power function? If C
    is running on a CISC processor, theres probably
    a small number of Assembly Level instruction that
    can do the job. In fact, on an Intel processor,
    theres an instruction for doing powers of
    numbers.
  • On a RISC processor, there is no such
    instruction, so the C Language Runtime Library
    has to do the calculation, using the RISC
    instructions (multiply, divide, etc.) that it has
    available from the RISC language set.
  • Whether its done in hardware (CISC) or in
    software (RISC), the calculation is based on a
    mathematical entity called a Binomial Expansion.

22
The Problem
  • The Binomial Expansion

One of the things thats interesting about this
is that it goes on forever! Does it converge or
diverge?
If n is very large there will be many terms. If
X gt 1, then Xn may get larger and larger.
23
Project 6 9 Project Evaluation
  • Name_____________________________________________
    ____________
  • Does the program decomposition from Project 6
    work on your HLL code?
  • Is there a complete set of test cases?
  • Does the High Level Language program work for
    this set of test cases?
  • Based on your experience with Project 7, do you
    have a new program decomposition? Is this new
    decomposition radically different from Project 6?
  • Is there a Project 8 handed in that has just the
    structure of the Assembly code that will be
    handed in? Is it handed in BEFORE Project 9?
  • Does the structure of Project 8 match the program
    decomposition from Project 6 or from the revised
    decomposition?
  • Does Project 8 include how the variables will be
    used?
  • Does Project 8 include headers for each of the
    routines used? Do these headers describe what
    the routine will do and what variables will be
    used in the routine?
  • Does Project 9 work on the student test cases?
Write a Comment
User Comments (0)
About PowerShow.com