lecture 15 - Th The University of Texas at Dallas Erik...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Erik Jonsson School of Engineering and h U i it f T t D ll Computer Science The University of Texas at Dallas Loops in SPIM Iterative loops are easy to structure in a higher-level language, in which instruction sets may be repeated innumerable times via “do,” “if,” or “for.” In assembly language, there are no such commands; loop details must be designed by the programmer. That is, in assembly language, the programmer must do all the “dirty work” of creating the loop. y g p This includes writing loop software, keeping track of the number of loop passes, and deciding via a test when © N. B. Dodge 09/09 Lecture #15: Constructing Loops in SPIM 1 the looping software has completed its job.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Erik Jonsson School of Engineering and h U i it f T t D ll Computer Science The University of Texas at Dallas Loops (2) Requirements for an assembly language loop: Entry function to get into the loop (“call function”). Counter function (if a counter is used) : Counter software to keep track of passes through the loop. Initialization function to set the counter to zero or preset it to some other appropriate number before starting the loop. Increment (decrement) function for the counter. Assembly language instruction set that performs the desired function within the loop. Control statement (branch or set) that compares the number of passes in the counter (tests) or otherwise determines when to © N. B. Dodge 09/09 Lecture #15: Constructing Loops in SPIM 2 exit the loop at the correct time.
Background image of page 2
Erik Jonsson School of Engineering and h U i it f T t D ll Computer Science The University of Texas at Dallas A Loop Program: Reversing a String The following is an example of building a loop program. Problem: Assume a data block (ASCII characters) is transmitted your MIPS computer to be displayed, but it was transmitted in to your MIPS computer to be displayed, but it was transmitted in reverse order. The sequence must be inverted to print out. Further, transmission control characters must be stripped out of e data before displaying, including *,&, <, >, and #, the last of the data before displaying, including , &, , , and #, the last of which is used to denote end-of-transmission. This is not a big problem today, as data transmission protocols are ery consistent. However assume that it’s a few decades ago, when ve y co s s e . oweve ssu e s ew dec des go, w e data transmission was very unpredictable and standards were few. The problem is to invert the string of characters and print to the console, stripping out the control characters. © N. B. Dodge 09/09 ,p p g Lecture #15: Constructing Loops in SPIM 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Erik Jonsson School of Engineering and h U i it f T t D ll Computer Science The University of Texas at Dallas Analysis To print out reversed characters in a string, there are two options: Start at the far end of the characters and come forward, printing a aracter at a time. character at a time.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/16/2009 for the course EE 2310 taught by Professor Dodge during the Spring '09 term at University of Texas at Dallas, Richardson.

Page1 / 26

lecture 15 - Th The University of Texas at Dallas Erik...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online