# Computer Project Synopsis Sample - PowerPoint by msv19261

VIEWS: 1,271 PAGES: 15

• pg 1
```									Computer Organization
Project 4

Prof. Jerry Breecher
CSCI 140
Spring 2004

Computer Organization - Project 4   1
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”.

We‟re 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.

Computer Organization - Project 4            2
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

A.   Write your calculator first in a High Level Language.
B.   Write a test plan.
C.   Test out your HLL calculator using your test plan.
D.   Write the code in MIPS Assembler.
E.   Use your test plans to convince yourself that your code works.
F.   Demonstrate to me the success of your functions.

Computer Organization - Project 4          3
What You Will Do In This Lab.

Groundrules:

Credit for Projects comes in multiple flavors:
1.  Write test plans for these routines. These are due by class
time on Thursday.
2.  Do the project (whether during the lab hour or at some other
time), and satisfy me that it works.
3.  Show me properly documented code.
4.  Explain verbally how your code works.

Working independently:
Same as last week.

Computer Organization - Project 4       4
SPIM Project #4
Write a calculator with the
following properties:                             An example run
– Program is capable of implementing
the following operations:                <run>
• Add two numbers and print
result                              This program was written by XXX
• Subtract two numbers and print       Enter an operation: 3 + 7
result                              Result is:       10
• Multiple two numbers and print       Enter an operation: -7 / 3
result
Result is:       -2
• Divide two numbers and print
results                             Enter an operation: -3 - -5
• Quit                                 Result is:       2
– User inputs the operation                Enter an operation: quit
– Program prints out the answer.           Thank you for playing.
– Program runs until “quit” operation
is selected.
– Integer arithmetic only.
– Numbers can be positive or negative

Computer Organization - Project 4               5
SPIM Project #4
Let‟s define that input VERY carefully!
Here’s the format for the input string:
{Number} + { Req-Space + Operator +Req-Space + Number} + Return

Number             == Sign + Nonzero-Digit + { Digit }*
Sign               == „-‟ | „+‟ | „‟                   Means it can be minus, OR plus, OR nothing
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.

Computer Organization - Project 4                                     6
SPIM Project #4
Let‟s define that input VERY carefully!
Which of these inputs have a format that’s legal for this project?

7+9
-4 - -8
This is a blank line.
7*9
+39 / 013

When you write your test plan, you don’t need to check illegal
formats. But if the input has a correct format, your calculator is
expected to handle it.

Computer Organization - Project 4                   7
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!
Computer Organization - Project 4       8
SPIM Project #4
Preparing to write MIPS code.
Write a test plan:
• Devise a test plan for your calculator.
• You don’t need to test all possible cases, but you DO need to cover the
complete sample set.

Computer Organization - Project 4              9
Useful Routines
BZERO(3)         Linux Programmer's Manual             BZERO(3)

NAME
bzero - write zeros to a byte string

SYNOPSIS
#include <string.h>

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.

Computer Organization - Project 4                10
Useful Routines
# ####################################################################
# BZERO - Sets n bytes in a buffer/string to <NUL>.
#           Watch out! The routine zeros out everything that you
#           tell it to!
#
# Here's the code in C:
#      for ( i = 0; i < n; i++ )
#     destination_string[i] = '\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:
blez \$a1,bzero3            # Make sure we have more to do.
sb     \$t0,(\$a0)
addi \$a0,\$a0,1             # Aim at the next byte in the buffer
addi \$a1,\$a1,-1            # Decrement cntr of # bytes to do.
bnez \$t0,bzero2
bzero3:
lw     \$ra,0(\$sp)
addu \$sp,\$sp,8
jr     \$ra

Computer Organization - Project 4            11
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.

Computer Organization - Project 4            12
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 <SP>
beq   \$a0, 9, isspace_done          # Branch if <TAB>
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
#         \$v0 == 0 otherwise.
# ####################################################################
isdigit:
addi \$v0,\$zero,0
blt   \$a0, 48, isdigit_done         # Nope - less than "0"
bgt   \$a0, 57, isdigit_done         # Nope - more than "9"
addi \$v0,\$zero,1                    # Set the return to 1
isdigit_done:
jr    \$ra

Computer Organization - Project 4                13
Useful Routines
STRLEN(3)         Linux Programmer's Manual          STRLEN(3)

NAME
strlen - calculate the length of a string

SYNOPSIS
#include <string.h>

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)

Computer Organization - Project 4                       14
Useful Routines
# ####################################################################
#
# STRLEN - Determine the length of a string. Count the number of
#            characters before, but not including, the terminating
#            <NUL>. If there's no <NUL>, 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
b     strlen2
strlen3:
move \$v0,\$a0            # This is the address containing a <NUL>
lw    \$a0,4(\$sp)        # This is the starting address
sub \$v0,\$v0,\$a0         # The difference = string length
lw    \$ra,0(\$sp)
addu \$sp,\$sp,8
jr    \$ra               Computer Organization - Project 4             15

```
To top