CMPE12, Spring 2012, Section 01: Lab 6: Double Reversal

Lab 6: Double Reversal

Lab Objective

When you interview for a job, each interviewer you meet asks you several questions, and tries to gauge your adaptability and skillset based on your answers.

You are interviewing for a coveted assembly language programming job. You don your best geeky computer-themed shirt, your cleanest jeans, and nicest sneakers, and go to meet your interviewer. She looks you over, evidently pleased with your attire, and asks:

Suppose you have a sentence, such as I like cat food. How do you reverse the words of the sentence? Express your answer in LC-3 assembly language.

I like cat food (original)

food cat like I (solution)

You will be scored on the elegance of the implementation of solution, your code style, your use of data structures, and your documentation, as well as the code itself.

You MUST work together with a partner to develop both the algorithms AND the design. You should make sure that you are designing out your entire flow chart and use of registers, stack, memory, etc BEFORE beginning your programming. Remember to also step through your code, and to verify that registers contain the values they are supposed to before asking the TA's / Tutor's to go through your code as this is the first thing that we are going to do to assist you.

Lab tutors: Go over these topics

Your lab tutor will cover the following topics in the first 40 minutes of lab.

  • What are the differences between the following instructions? Why are they grouped together?
    • Group 1: LD, LDR, LEA, LDI
    • Group 2: ST, STR, STI
    • Group 3: JSR, JSRR
    • Group 4: JMP, BR
  • What is a stack, how to use a stack pointer, and stack convention (top element is empty or full? increment stack pointer first or after data?)
  • What is a string pointer? How do PUTC and PUTS work?

Lab 6: Double Reversal in detail

In the interview, the interviewer will expect to input a sentence. Then you will print the sentence with the words reversed.

What's required

A lab write-up, readme, and lab6.asm

Procedure

Here is how the interviewer expects your program to run.

  1. Display a greeting.
  2. Allow the user to input a string -- that is, a bunch of characters -- no more than 40 characters long. The sentence will end in a newline, and will contain no punctuation except spaces. You may assume that the interviewer's sentence will not be more than 40 characters long, so you don't have to check for a string that's too long.
  3. Multiple spaces must be treated as a single space. The sentence will not start with a space; the first character will not be a space, so you don't have to check for that. As before, a newline by itself exits the program.
  4. Reverse the words in the string -- you can display any intermediate steps you used, if you like.
  5. Display the result.
  6. Repeat the program (go to 1).

Additionally, to impress the interviewer, your program must...

  • Use functions (JSR/JSRR/RET) rather than the "spaghetti-code" implementation of branching absolutely everywhere (spaghetti-code will not get you called back for another interview)
  • Use subroutines which save and restore critical registers (callee-saved)
  • Have a main procedure from which everything is called -- much like public static void main() in Java or int main()in C
  • Use a stack, with stack operations push, pop, and know when the stack is empty or full with functions isEmpty and isFull, respectively
  • Have proper error-checking for all weird cases
  • Have detailed implementation notes in the lab write-up

Grading template

This is a suggested grading rubrik. Your tutor may or may not use this rubric to grade by, but it is a good general guideline before submitting your code to check off these points.

  • Nice user interface
  • String input as described
  • String is output in reverse order as described
  • Multiple spaces treated as one, newline by itself exits, program loops ad nauseum
  • Code clean and well-documented
  • Use of C/Java Style "main" and function calls with JSR/JSRR and RET
  • Stack functions push, pop, isEmpty, isFull

    Total: 50 points