Computer Organization - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Computer Organization

Description:

We're going to build this calculator in stages: ... Write a calculator with the following properties: ... Devise a test plan for your calculator. ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 16
Provided by: jb20
Category:

less

Transcript and Presenter's Notes

Title: Computer Organization


1
Computer Organization
  • Project 4
  • Prof. Jerry Breecher
  • CSCI 140
  • Spring 2004

2
What You Will Do In This Lab.
  • The purpose of this project is to eventually get
    your calculator program to the point where you
    can utter something like
  • 3 5 4 / 2
  • To do this requires that you be able to take in
    all the input on one line, as an ASCII string,
    and then parse that string in order to separate
    out the different components or fields.
  • Were going to build this calculator in stages
  • Project 3 Write some of the background
    routines.
  • Project 4 Be able to handle A op B.
  • Project 5 Finish the entire calculator.

3
What You Will Do In This Lab.
  • So the assignment for this week looks like this
  • Write a calculator that can handle operations
    like
  • Num1 -/ Num2
  • Write your calculator first in a High Level
    Language.
  • Write a test plan.
  • Test out your HLL calculator using your test
    plan.
  • Write the code in MIPS Assembler.
  • Use your test plans to convince yourself that
    your code works.
  • Demonstrate to me the success of your functions.

4
What You Will Do In This Lab.
  • Groundrules
  • Credit for Projects comes in multiple flavors
  • Write test plans for these routines. These are
    due by class time on Thursday.
  • Do the project (whether during the lab hour or at
    some other time), and satisfy me that it works.
  • Show me properly documented code.
  • Explain verbally how your code works.
  • Working independently
  • Same as last week.

5
SPIM Project 4
  • Write a calculator with the following properties
  • Program is capable of implementing the following
    operations
  • Add two numbers and print result
  • Subtract two numbers and print result
  • Multiple two numbers and print result
  • Divide two numbers and print results
  • Quit
  • User inputs the operation
  • Program prints out the answer.
  • Program runs until quit operation is selected.
  • Integer arithmetic only.
  • Numbers can be positive or negative

An example run
This program was written by XXX Enter an
operation 3 7 Result is
10 Enter an operation -7 / 3 Result is
-2 Enter an operation -3 - -5 Result is
2 Enter an operation quit Thank you
for playing.
6
SPIM Project 4
  • Lets define that input VERY carefully!

Heres the format for the input string Number
Req-Space Operator Req-Space Number
Return Number Sign Nonzero-Digit
Digit Sign - White-Space-Char
SP TAB Digit 0 1 2 3 4
5 6 7 8 9 Nonzero-Digit
1 2 3 4 5 6 7 8
9 Sp Space Character An ASCII
32 TAB Tab Character An ASCII 09
White-Space White-Space-Char Req-Space
White-Space-Char Operator -
/ Return /n optionally
1 or 0 occurrences. optionally 1 or
more occurrences. optionally 0 or
more occurrences.
Means it can be minus, OR plus, OR nothing
7
SPIM Project 4
  • Lets define that input VERY carefully!

Which of these inputs have a format thats legal
for this project? 7 9 -4 - -8 79 39 /
013 When you write your test plan, you dont
need to check illegal formats. But if the input
has a correct format, your calculator is expected
to handle it.
This is a blank line.
8
SPIM Project 4
  • Preparing to write MIPS code.
  • Figure Out The Logic
  • Write your calculator in a High Level Language.
  • Use in your HLL the routines having the same
    functionality as in MIPS code you have available.
  • Your previous calculator logic Proj 2
  • Itoa Proj 2
  • Strcpy Proj 2
  • Strncpy Proj 3
  • Strchr Proj 3
  • Strpbrk Proj 3
  • Atoi Proj 3
  • Bzero Proj 4
  • Isspace Proj 4
  • Isdigit Proj 4
  • Strlen Proj 4
  • If, in your HLL code you use routins other than
    those shown here, you will need to code them!

9
SPIM Project 4
  • Preparing to write MIPS code.
  • Write a test plan
  • Devise a test plan for your calculator.
  • You dont need to test all possible cases, but
    you DO need to cover the complete sample set.

10
Useful Routines
  • BZERO(3) Linux Programmer's Manual
    BZERO(3)
  • NAME
  • bzero - write zeros to a byte string
  • SYNOPSIS
  • include
  • void bzero(void s, size_t n)
  • DESCRIPTION
  • The bzero() function sets the first n
    bytes of the byte string s to zero.
  • RETURN VALUE
  • The bzero() function returns no value.

11
Useful Routines

  • BZERO - Sets n bytes in a buffer/string to
    .
  • Watch out! The routine zeros out
    everything that you
  • tell it to!
  • Here's the code in C
  • for ( i 0 i
  • destination_stringi '\0'
  • in a0 - address of buffer
  • in a1 - Number of bytes to be zeroed.
  • returned NONE
  • destroyed a0 - a1, t0

  • bzero
  • subu sp,sp,8 save sp and destination
    address
  • sw ra,0(sp)
  • move t0,zero Get a zero so we can store it
    later.
  • bzero2

12
Useful Routines
  • Character Routines
  • int isdigit (int c)
  • int isspace (int c)
  • isspace()
  • For our project we say a white-space is a
    space (ASCII 32), horizontal tab (ASCII 9) or NL
    (ASCII 10).
  • isdigit()
  • checks for a digit (0 through 9).
  • RETURN VALUE
  • The values returned are nonzero if the
    character c falls into the tested class, and a
    zero value if not.

13
Useful Routines

  • ISSPACE - Determines if a character is a white
    space.
  • We define a white space as a space,
    horizontal tab, or New Line.
  • Input a0 contains the character to be
    analyzed.
  • Returns v0 1 if a0 contains a WhiteSpace
    character.
  • v0 0 if a0 contains other than
    white space.

  • isspace
  • li v0,1
  • beq a0, 32, isspace_done Branch if
  • beq a0, 9, isspace_done Branch if
  • li v0,0 NOT found
  • isspace_done
  • jr ra

  • ISDIGIT - Determines if a character is a
    decimal digit.
  • Input a0 contains the character to be
    analyzed.
  • Returns v0 1 if a0 contains a
    0,1,2,3,4,5,6,7,8, or 9

14
Useful Routines
  • STRLEN(3) Linux Programmer's Manual
    STRLEN(3)
  • NAME
  • strlen - calculate the length of a string
  • SYNOPSIS
  • include
  • size_t strlen(const char s)
  • DESCRIPTION
  • The strlen() function calculates the
    length of the string s, not including the
    terminating \0' character.
  • RETURN VALUE
  • The strlen() function returns the number
    of characters in s.
  • SEE ALSO
  • string(3)

15
Useful Routines

  • STRLEN - Determine the length of a string.
    Count the number of
  • characters before, but not including,
    the terminating
  • . If there's no , it just
    keeps counting.
  • in a0 - address of buffer containing
    string
  • returned v0 contains the number of
    characters
  • destroyed t0

  • strlen
  • subu sp,sp,8 save sp and destination address
  • sw ra,0(sp)
  • sw a0,4(sp)
  • strlen2
  • lb t0,0(a0) Get the next character
  • beqz t0,strlen3 Make sure we have more to do.
  • addi a0,a0,1
Write a Comment
User Comments (0)
About PowerShow.com