CMPE12, Spring 2012, Section 01: Lab 5: Decimal Converter

Lab 5: Decimal Converter

Adapted with permission from Cyrus Bazeghi


Lab Objective:

Now that we are moving into programming in the lab, it is important for you to practice good programming practices.  When programming in assembly this is especially true as assembly is not a pretty or easily readable language.  Being clear with your register usage is very important, also, having a clear plan for your program is essential, thus for all programs in this class you will be required to create flowcharts.  Once a flowchart is created the problem has been solved, now you need to just map your solution to assembly code.  For this lab you are REQUIRED to work in a programming pair. In the event of an odd number there will be one group of three. In order to receive credit BOTH partners must turn in the assignment using the submit command from the unix servers.

Part A:

The tutors/TA will present you the Program Flow lecture in the lab.  The purpose of this lecture is to go over some of the basics of what a programmer does and the usage of flowcharting to solve a simple problem.  Once the problem is solved it is easy to then implement it in whatever programming language you are required to use.  Here is the lecture in PDF.

Part B:

You know how to get character input from the user.  Extend this to write a program to input and output integer values.  Here are the specifications:

  • Print out a greeting message.
  • Ask for a decimal number followed by a carriage return.
  • Do NOT expect the user to only input valid digit characters (0-9) and possible a leading negative sign (-).
  • Convert the string of digits entered into a two’s complement number (you will have to do something special for the negative sign).
  • Print the number out in binary.
  • Repeat until the user wants to quit.

Pretty straight forward but this will require the use of loops and procedure calls. 

Part C:

Now that you have a binary representation of the string, you can extend this to have the following functionality:

  • Check for invalid inputs, i.e. make sure they type in only ‘0’ to ‘9’ and ‘-‘, and only in the correct locations.
  • Create an additional printing procedure that prints out your number in HEX.

Extra Credit:

You MAY choose to do the following for 5 pts extra credit each:

  • Print out the OCT representation of the number input by the user.
  • Print out the DEC representations of your numbers (you need to actually do the conversion back, not just store the string entered).

Lab Requirements:

You must do the following for this lab:

  • Create a flow chart for your program first, submit this to the TA/tutor when you demonstrate your program, here is an example of one €œLab5_Flowchart.pdf
  • Create the following procedures:
  1. A get decimal integer procedure, it will read a character string and convert to an integer.
  2. A print binary procedure, it will just print out the bits that are stored in a register as a string of 16 0's and 1's.
  3. Print HEX and print OCT, printing out the contents of a register as a string of 0-9,A-F (for HEX) and 0-7 (for OCT) ((Octal only for extra credit)).
  • Print out appropriate messages and prompts and have some way to quite your program when finished.

See the example below for how this might work.  Give the program your own personal look and feel.

Collaboration: You are allowed to discuss this lab with other students on this lab only from a high level, such as discussing your flowcharts, NOT by working on code together.

 

You are REQUIRED to work in a pair on this lab assignment. You can only be a partner with someone in your lab section.  You are agreeing to only work together when programming.  You are NOT allowed to work on it separately and then share results. Example of possible output:

Your output does not have to look exactly like this, make it your own program.  You just need to make it useable so that anyone sitting down would know how to use it.  However, you should protect against invalid input.

 

 

Welcome to Cyrus’ conversion proggie

 

Enter a decimal number or X to quit:

>12

Thanks, here it is in binary

0000000000001100

 

Enter a decimal number or X to quit:

>-3

Thanks, here it is in binary

1111111111111101

 

Enter a decimal number or X to quit:

>X

Bye.  Have a great day.

----- Halting the processor -----

 

Part C Version

 

Welcome to Cyrus'€™ advanced conversion proggie

 

Enter a decimal number or X to quit:

>12

Thanks, here it is in dec, bin, hex, and oct

12

0000000000001100

000C

000014

 

>-3

Thanks, here it is in dec, bin, hex, and oct

-3

1111111111111101

FFFD

177775

 

>X

Bye.  Have a great day.

----- Halting the processor -----

 

Files to Submit:

  • Lab5.asm
  • README  - tell how to run the program
  • Flowchart to TA/Tutor when demonstrating
  • Lab5_Report -€“ needs to discuss the algorithm(s) you implemented and that you drew in the flow chart.

 

Check-off: Each pair must demonstrate this lab to the TA/tutor, either before submission or within one week of submission.   To be considered on time you must have submitted everything by the due date.

Grading template:

Grading Criteria Basic specifications: Does your code ...?

___ (2 pts)  Print greeting message and quit when prompted?

___ (5 pts)  Check for valid input?

___ (10 pts)  Converts character decimal string into a 2SC number?

___ (10 pts) Print as a binary string?

___ (10 pts)  Print as a hexadecimal string?

___ (5 pts)  Work with negative input?

___ (5 pts)  Have a good flow chart detailing the program flow.

___ (3 pts)  Have required comments in the code (block personal info, line comments, register usage)

Extra Credit:

___ (5 pts)  Print as a octal string?

___ (5 pts)  Print as a decimal string?

Your Lab5 Score:___ points out of 50

Attachments