{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

Erik Jonsson School of Engineering and Th 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; l d t il t b d i d b th 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. This includes writing loop software, keeping track of the number of loop passes, and deciding via a test when th l i ft h l t d it j b © N. B. Dodge 09/09 Lecture #15: Constructing Loops in SPIM 1 the looping software has completed its job.

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

View Full Document
Erik Jonsson School of Engineering and Th 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.
Erik Jonsson School of Engineering and Th 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 to 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 the 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 very consistent. However assume that it’s a few decades ago, when 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 Lecture #15: Constructing Loops in SPIM 3

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

View Full Document
Erik Jonsson School of Engineering and Th 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 character at a time. character at a time.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}