Computer Organization - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Computer Organization

Description:

... my webpage see the bottom of the page at http://babbage.clarku.edu/~jbreecher ... http://babbage.clarku.edu/~jbreecher/comp_org/lectures/AppendixA-SPIM.ppt ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 13
Provided by: jb20
Category:

less

Transcript and Presenter's Notes

Title: Computer Organization


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

2
What You Will Do In This Lab.
  • The purpose of this lab is to help you become
    familiar with simple Assembler programs and the
    use of SPIM, the hardware simulator. This means
    being able to do editing, and Spimming of these
    programs.
  • You have one task before you
  • 1. Using your favorite editor, type in (or
    paste) the program given later in this document.
    Assemble it and run it and show that it produces
    the result you would expect.

3
What You Will Do In This Lab.
  • Groundrules
  • Credit for Labs and Projects comes in two
    flavors
  • Showing up for lab (at the appointed hour) gets
    you credit for lab.
  • Doing the project (whether during the lab hour or
    at some other time), and satisfying me that it
    works gets you project credit.
  • For this weeks lab/project, you will conduct the
    project as described on a page later in this
    document.
  • You will get checkoff credit when I see that it
    works and produces the results we know its
    supposed to have.

4
Where To Get Documentation
  • There are many sources of information to help you
    with this lab. Here are some of those sources
  • Learning UNIX
  • These skills can be acquired (I hope) from the
    documentation available on my webpage see the
    bottom of the page at http//babbage.clarku.ed
    u/jbreecher
  • SPIM can best be learned from the summary lecture
    at
  • http//babbage.clarku.edu/jbreecher/comp_org/lect
    ures/AppendixA-SPIM.ppt
  • Along with Appendix A of your text.
  • If you dont like these documents, there are
    plenty of other ones out on the web. Go wild!

5
Sample SPIM Programs (on the web)
  • multiply.s multiplication subroutine based on
    repeated addition and a test program that calls
    it.
  • http//babbage.clarku.edu/jbreecher/comp_org/labs
    /multiply.s
  • fact.s computes factorials using the multiply
    subroutine.
  • http//babbage.clarku.edu/jbreecher/comp_org/labs
    /fact.s
  • sort.s the sorting program from the text.
  • http//babbage.clarku.edu/jbreecher/comp_org/labs
    /sort.s
  • strcpy.s the strcpy subroutine and test code.
  • http//babbage.clarku.edu/jbreecher/comp_org/labs
    /strcpy.s

6
An Example Program

  • SAMPLE1.S - This program provides a sample of
    how to read a string
  • from the terminal.
  • in none
  • out none
  • Useful Pages In The Text
  • A22-23 Register usage for subroutines
  • A46-47 Use of SPIM
  • A48-49 System Call usage
  • A55-74 The instructions, both native and
    pseudo.
  • Update History
  • January 02 - Created


7
An Example Program
  • main
  • subu sp,sp,8 Make space on the stack
  • sw ra,0(sp) Put the return address on the
    stack
  • sw fp,4(sp) Put the frame pointer on the
    stack
  • We're going to do a system call - to do IO to
    the console. This
  • requires loading v0 with the type of call to
    be done. Registers
  • a0 - a3 then take on meanings dependent on
    the call.
  • Note that we are doing "pseudo instructions".
  • li load immediate, la load address
  • li v0, 4 Prepare to do a print_string
  • la a0,prompt Get the address where the string
    is.
  • syscall

8
An Example Program
  • Get a data string from the terminal. According
    to the definition
  • of the string input, this data has a null
    termination. So if we read
  • in "ABC", the buffer contains ABCltnulgt
  • li v0,8 Prepare to do an input_string
  • la a0,buffer Where data will be placed
  • lw a1,buf_len Size of buffer to hold the data
  • syscall

9
An Example Program
  • Print out the input string. We'll print out
    the ascii value of
  • the input line. We do this by reading in the
    byte (character)
  • that we entered, but then printing it out as if
    it's an integer.
  • la s0,buffer Use s0 to aim at byte loc. in
    buffer
  • print_loop
  • la a0,spacer Print out a spacer between chars
  • li v0,4 Do a string output
  • syscall
  • lb a0,(s0) Get the char from input buffer
  • Use a0 to give the char to the syscall.
  • li v0,1 Prepare to do an output_integer
  • syscall
  • addi s0,s0,1 Aim at the next byte in the
    buffer
  • bnez a0,print_loop

10
An Example Program
  • We're done - get out of the program
  • lw ra,0(sp)
  • lw fp,4(sp)
  • addu sp,sp,8 Restore the stack pointer
  • jr ra Jump to the address in the ra register

11
An Example Program

  • This is the data/static portion of the file.

  • .data
  • prompt
  • .asciiz "Give me a string "
  • spacer
  • .asciiz " "
  • buffer
  • .space 100
  • buf_len
  • .word 100

12
Project 1
  • So youve just seen the code for this lab. We
    will be going through it so that you understand
    what it does.
  • Type in the program given on the last few pages
    using your favorite editor. In this example, the
    source file is named proj1.s
  • (I will actually enter this code and run it in
    SPIM so you can see how its done.)
  • Get SPIM running.
  • Debug the program - (if you can type perfectly
    there will be nothing to debug!)
  • Run the program.
Write a Comment
User Comments (0)
About PowerShow.com