Exercise6 - 0306-250 Assembly Language Programming Fall...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Fall 2009 Laboratory Exercise Six: Decimal Adding Machine Using BCD Numbers and Operations This exercise investigates input, storage, addition, and output of packed BCD numbers. The objective of this exercise is familiarization with BCD format and operations. An assembly language program is written to provide the functionality of a decimal adding machine via polled SCI serial I/O and BCD operations. Prelab Work Following the specifications below and the notes you have taken in lecture, write subroutines for adding and printing BCD numbers. You must write the subroutines so that the no registers other than CCR have changed values after return (RTS). · AddBCD: Adds one packed BCD number to another: X = X + Y. Each number and the sum will have the same number of bytes, which is specified in B. Register X has the address of the first byte of X, and register Y has the address of the first byte of Y. If the sum requires more bytes than specified in B, AddBCD should return with the CCR’s C bit set; otherwise, C should be clear when AddBCD returns. · PutBCD: Transmits through SCI0 the ASCII representation of the packed BCD number whose address is in X. The number of bytes in the number is specified in B. Work on the decimal adding machine program specified below to be demonstrated in the lab procedure. Warning: this exercise may appear easier than it really is. Despite the rather simple functionality, significant effort is required to implement the user interface and input of BCD numbers in assembly language. Program Specification You need to write a program that uses the subroutines from your prelab work to provide a user interface and functionality for a decimal adding machine. Below is the sequence of operations the program must perform. 1. Initialize an 8-digit packed BCD variable Total to 0. 2. Initialize the HCS12 SCI for polled serial I/O using a format of eight data bits, no parity, and one stop bit—as in Lab Exercise Four. 3. Using the properly documented PutString subroutine from Lab Exercise Four, output the character string below to the terminal screen followed by a carriage return Page 1 of 4 0306-250 20091 Lab Ex. 6: Decimal Adding Machine Using BCD Numbers and Operations Page 2 of 4 character ($0D) and a line feed character ($0A) to advance the cursor to the beginning of the next line, and then output “>” as a prompt, as shown below. Enter up to an 8-digit number to add > 4. Using the properly documented GetChar subroutine from Lab Exercise Four, accept up to 8 digits or single-character commands typed on the terminal keyboard, as specified below. (For the output specified below, use the properly documented PutChar and PutString subroutines from Lab Exercise Four.) · Enter (i.e., <CR>): Move the cursor to the beginning of the next line, print T followed by the current value of Total using your PutBCD subroutine, move the cursor to the beginning of the next line, and print a new prompt > character. > T12345678 > · + or =: Produce the same result as Enter, except the character typed is echoed first. >+ T12345678 > · C or c: Echo the character typed, clear Total, and follow with the same behavior as for Enter. >C T00000000 > · H or h: Echo the character typed, move the cursor to the beginning of the next line, print a brief explanation of the single-character commands, move the cursor to the beginning of the next line, and print a new prompt > character. >H Your help text goes here. > · Up to 8 decimal digits (i.e., 0-9)—number entry mode: echo each digit typed, and store the digits to represent the number entered in an 8-digit packed BCD number. Once the first digit is entered only additional digits and commands listed below are allowed. Number entry mode should terminate under the following conditions and should affect Total as indicated for each condition. – More than 8 digits entered—invalid number; Total is not changed. Echo the ninth digit, print an error message/instruction that only up to 8 digits are allowed, move the cursor to the beginning of the next line, and print a new prompt > character. – X or x—end number entry mode without changing Total. Echo the character typed, move the cursor to the beginning next line, and print a new prompt > character. – Enter (i.e., <CR>)—number entry is complete for adding to Total. Move the cursor to the beginning of the next line, store the number in packed BCD format, and add it to Total using your AddBCD subroutine. If the addition produced overflow, clear Total, print OVERFLOW, and move the 0306-250 20091 Lab Ex. 6: Decimal Adding Machine Using BCD Numbers and Operations Page 3 of 4 cursor to the beginning of the next line. Regardless of the outcome, print T followed by the new value of Total (which will be 0 if there was overflow), move the cursor to the beginning of the next line, and print a new prompt > character. – + or =—number entry is complete for adding to Total. Produce the same result as Enter, except the character typed is echoed first. – Any other character (including C, c, H, or h)—entry is invalid; Total is not changed. Echo the character typed, print an error message/instruction that input was invalid, move the cursor to the beginning of the next line, and print a new prompt > character. 5. Repeat step 4. The program must use the subroutines from prelab work for BCD operations. The subroutines must comply with the prelab specifications. Also, make sure each subroutine is properly documented (i.e., has a comment header block that documents these aspects): · Description of subroutine functionality, · Subroutines called list, · Input parameter list, · Output parameter list, and · Register modification list. Lab Procedure 1. Create a new CodeWarrior directory (folder) and project on your X: drive for this exercise. 2. Write a properly commented and properly formatted HCS12 assembly language program to implement a decimal adding machine that inputs, adds, and outputs numbers stored in BCD format, according to the preceding specification. 3. Assemble the program in CodeWarrior compiler to create a listing file. 4. Link the program in CodeWarrior to create a linker map file. 5. Test your program. Make sure to test this sequence of inputs/operations, which must be demonstrated to the instructor. a. Input of an 8-digit number, addition of another 8-digit number, and output of the total. b. Input and addition of a 3-digit number to result of a, and output of new total. c. Press of Enter key. d. Input of a 9-digit number. e. Input of Enter, +, and = in both command and number entry modes. f. Input of X and x. g. Input of C and c. h. Input of other characters. 6. Examine the HCS12 memory location containing Total after various inputs above. 0306-250 20091 Lab Ex. 6: Decimal Adding Machine Using BCD Numbers and Operations Page 4 of 4 7. Print your listing file, linker map file, and grading sheet, and then demonstrate steps 5-7 for your lab instructor. Following demonstration, print the terminal screen output, and have your lab instructor sign your printed pages. Report Write a report consisting of the following sections. · Abstract · Procedure · Results F Your results should demonstrate correct operation of the decimal adding machine for the cases tested in lab procedure step 5. · Conclusion Your writing should follow the rules of professional technical writing and should meet the specifications in “Laboratory and Report Guidelines” on the course reference material web page. Staple your cover page, report, listing file, linker map file, and grading sheet (in that order), and submit them at the beginning of the next lab session. Late reports are penalized 20% per day late, as defined in “Laboratory and Report Guidelines.” ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online