ECE 3120
Lab 8 – Stack and Subroutines	
The purpose of this lab is to reinforce your basic programming skills with the 68HSC12 using
subroutines with stack programing.
    1- Pre-lab:
This must be completed before coming to the lab and shown to the lab instructor at the
start of the lab session, and submitted with the final report.
    1- Prepare the first draft of the program described below. The program should contain
       directives and comments. Comments are a must
    2- Calculate the expected results by hand in hex.
Approved: Lab TA _____________________ Date ____________
PROGRAMMING ASSIGNMENTs:
Write a fully-commented program called Lab8.asm for the Dragon12 board, including
appropriate directives and labels for memory operands and constants. Comments should mostly
describe WHAT you are accomplishing toward solving the problem, not HOW each instruction
works alone. Every instruction may not have a comment, but small groups of instructions must
have explanatory comments. The data should be stored starting from address $1000, the stack
should start at $2000 (SP = $2000), and the program should start execution at address $3000.
The program should do the following:
    The program calls a subroutine called word_processor that can count the number of
    uppercase letters, lowercase letters, digits (0 to 9), and words, contained in a given string
    called String1. String1 is terminated by a special character 0, e.g., “Hello ECE3120
    students”,0. In addition, the subroutine reverses the string and coverts all the letters to
    uppercase. e.g., String1 should be “STNEDUTS 0213ECE OLLEH”,0. The pointer to the
    string to be processed (String1) is passed in X and the starting address of the reversed string
    is passed by stack. The statistics are return by stack.
    The main program should define String1 and initialize it with the values given in Tables 1-3.
    The main program should store the statistics in variables called uppercase_number,
    lowercase_number, digits_number, and words_number. Use the stack to reverse String1.
      Hints: assume there is either a space of dot after each work. The ASCII code of the digits
    are {$30, $31, …, $39} corresponds to {0, 1, .., 9}. The ASCII code of the lowercase letters
    are {$61, $62, …, $7A} corresponds to {a, b, .., z}. The ASCII code of the uppercase letters
    are {$41, $42, …., $5A} corresponds to {A, B, .., Z}.
                                            Page 1 of 3 
 
                                        ECE 3120
                              Lab 8 – Stack and Subroutines	
    2- In lab:
    1. Enter the code, assemble it, and download it into the Dragon12 board using Code
       Warrior.
    2. Use the single step, run to cursor, or breakpoint procedures to debug the programs.
       Ensure that the programs works as it is supposed to.
    3. Test the proper operation of the program:-
Table 1:
              String1              “Welcome to ece3120 Stacks and Subroutines”, 0
       uppercase_number
       lowercase_number
           digits_number
           words_number
           Reversed string
Draw diagrams showing the contents of the stack and SP each time the stack changes.
Table 2:
         String1             “WELCOME TO ECE3120 STACKS AND SUBROUTINES”, 0
    uppercase_number
    lowercase_number
      digits_number
     words_number
     Reversed string
Table 3:
            String1                     “welcome to stacks and subroutines”, 0
       uppercase_number
       lowercase_number
           digits_number
           words_number
           Reversed string
Approved:	Lab	TA	_____________________	Date	____________
                                           Page 2 of 3 
 
                                       ECE 3120
                             Lab 8 – Stack and Subroutines	
    3- Post lab:
Things to turn in as your Lab Report, attached in this order:
     1. [20 marks] This assignment sheet, with your name at the top, signed by the TA where
        shown. Your uncorrected pre-lab document (commented source code and expected
        results).
     2. [20 marks] A printout of the final files.
     3. [60 marks] Programs’ results:
        1) [8 marks] for Table 1.
        2) [8 marks] for Table 2.
        3) [8 marks] for Table 3.
        4) [25 marks] for case 1 in Table 1, draw diagrams showing the contents of the stack
           and SP each time the stack changes. Show how subroutine call/return instructions
           change the stack.
        5) [11 marks] for case 1 in Table 1, compute how many bytes you need to use in the
           stack, i.e., the maximum length of the stack = the maximum number of consecutive
           pushes.
                                            Page 3 of 3