Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lab 1 - Assemble and Trace
- Introduction
- The purpose of this lab was to become familiar with writing Assembly code using the CodeWarrior IDE.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- The HCS12 manual was used as a reference for the different Assembly instructions supported by the CPU
- The main instructions used were LDAA, ADDA, and STAA
- Data
- All values are encoded as part of the Assembly instructions
- (immediate addressing)
- Result
- Result 0x98 stored in memory location $210
- Discussion
- This was a good introduction to basic Assembly programming, and I became familiar with some basic Assembly instructions.
- This lab also got me used to the development environment and simulation tool.
- Lab 2 - Directives, Addressing Modes and Basic Arithmetic Programming
- Introduction
- The purpose of this lab was to use arithmetic operations in Assembly code.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- Similar instructions used as previous lab, but involved more registers and more arithmetic commands such as IDIV
- IDIV is inherently addressed, and operates on a fixed set of registers that needed to be loaded with the correct values before executing the instruction, and the results stored after executing the instruction
- Data
- Array stored at $2000:
- 50, 188, 63, 211, 3
- Result
- Sum stored at $2010-$2011 = 515
- Average stored at $2012-$2013 = 103
- Difference stored at $2014-$2015 = 412
- Discussion
- This lab used more commands and registers than the previous lab, and further familiarized me with the IDE and the HCS12 instruction set.
- This lab was a good introduction to 16-bit values and how certain registers on the HCS12 are different sizes than others.
- Lab 3 - Directives, Addressing Modes and Basic Arithmetic Programming
- Introduction
- The purpose of this lab was to use arithmetic operations in Assembly code.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- This lab used more instructions, especially control flow instructions
- (conditional and unconditional branch, jump)
- Comparison instructions were used to determine if a conditional branch was taken or not
- Data
- Array stored at $2000:
- 13, 127, 255, 88, 200, 58, 211, 101, 168, 44
- Result
- Unsigned minimum stored at $2200 = 0x0D
- Unsigned maximum stored at $2201 = 0xFF
- Difference stored at $2202 = 0xF2
- Signed minimum stored at $2203 = 0xC8
- Signed maximum stored at $2204 = 0x7F
- Discussion
- This lab was a good introduction to control flow instructions and comparison instructions, which were heavily used in the rest of the labs
- Lab 4 - Loop and Branch
- Introduction
- The purpose of this lab was to use loop instructions and branch instructions in Assembly language.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- This lab used similar instructions as the previous lab
- The Y register was used for the loop counter instead of the X register to simplify programming, since the D and X registers were used by the IDIV instruction, and there is no way to change IDIV to use a different set of registers
- Data
- Array stored at $1100:
- 133, 1200, 1390, 1900, 1881, 3939, 2010, 4080, 9801, 4592, 11, 22, 33, 3333, 3242, 5435, 8760, 9800, 2876, 9601
- Result
- Even count stored at $1000 = 0x09
- Odd count stored at $1001 = 0x0B
- Sum stored at $1002 = 0x14
- Discussion
- This lab built on the previous lab, and was more practice on using control flow instructions and looping.
- Lab 5 - Nested Loops
- Introduction
- The purpose of this lab was to use loop instructions and branch instructions in Assembly language, and to nest the loop instructions.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- This lab used similar instructions as the previous lab, but looped using both the X and Y registers, for a nested loop.
- Both loops work by initializing the register to 0, and incrementing it by one until it reaches a predefined value, and at that point the program will branch to the next part or finish.
- Data
- Array stored at $1000:
- 15, 20, 14, 13, 17, 9, 10, 5, 18, 7, 19, 8, 1, 3, 4, 11, 2, 6, 12, 16
- Result
- Results stored at $1000, replacing the original data:
- 0x14, 0x13, 0x12, 0x11, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01
- Discussion
- This lab was simple once I properly used registers to store loop indexes and the program’s state. Adding a nested loop within the first loop was not a challenge.
- Lab 6 - Subroutines
- Introduction
- The purpose of this lab was to use subroutines in Assembly language.
- Software and Hardware Used
- CodeWarrior IDE 5.2
- HCS12 Emulator
- Methods
- This lab was supposed to be based on subroutines, but I ended up using clever workarounds to avoid using a subroutine.
- I also did not want to make more than one comparison for each grade range. Instead of checking if a grade was more than one amount and less than another (inside of a range), I made 5 checks, checking if it was equal to or above each letter grade threshold. For each check that passed, a counter was incremented one time. After the CPU makes the 5 checks, it branches to a different part of the code depending on the value of the counter, and that code increments the correct location in memory for tallying the number of students that got each letter grade.
- Data
- Array stored at $1000:
- 76, 95, 87, 92, 87, 91, 91, 100, 79, 50, 81, 86, 100, 90, 77, 54, 87, 100, 87, 79, 77, 76, 100, 100, 82, 85, 100, 100, 51, 100, 83, 82, 100, 92, 92, 91, 66, 62, 80, 82, 79
- Result
- Results stored in memory as an array starting from $1050:
- 0x11, 0x0C, 0x06, 0x02, 0x03
- Discussion
- I did not feel like I understood how subroutines work on the HCS12 when I wrote the code, and wanted to see if I could efficiently write the program without using any subroutines.
- The program uses control flow instructions, but none of them use the stack to store a return address.
- I ended up practicing using subroutines before the next lab, and used them heavily in the next lab once I felt I sufficiently understood how they worked.
- Lab 7 - Parallel I/O
- Introduction
- The purpose of this lab was to use the HCS12 parallel ports to connect to LEDs and pushbuttons on the emulated Dragon12 development board.
- Software and Hardware Used
- CodeWarrior IDE 5.1 Special Edition
- HCS12 Emulator
- Methods
- This lab did not use many complex instructions, since reading or writing IO ports is as simple as storing a value into memory.
- This code runs on real hardware with very few modifications (move the entry point to the starting location of the Dragon12’s FLASH memory)
- Data
- None
- Result
- None
- Discussion
- This lab was a good introduction to the HCS12’s I/O ports, and the code worked almost right away on real hardware.
- I did not expect it to be this easy to use the I/O ports on the HCS12.
- Lab 8 - Parallel I/O (Hardware)
- Introduction
- The purpose of this lab was to upload the code from Lab 7 onto a real development board, and verify it works correctly on real hardware.
- Software and Hardware Used
- CodeWarrior IDE 5.1 Special Edition
- HCS12 Dragon12-Plus2 Development Board
- Methods
- The code from Lab 7 worked with very few changes required. The hardest part of this lab was getting the devkit to communicate with the computer at all.
- Data
- None
- Result
- None
- Discussion
- This lab was great practice for uploading a simple program to the Dragon12 devkit, and reminded me of many years ago when I uploaded my first Arduino program. Both boards were hard to initially set up and configure to connect with the PC, but once connected, were easy to program for.
- After getting the basic program to work correctly, I used the online HCS12 and Dragon12 reference manuals to add more features to the code. My second version of this lab controls the 7-segment displays, LCD screen, and buzzer in addition to the LEDs.
- Controlling the 7-segment displays proved to be a hard and time consuming task to perfect, since the digits are multiplexed and share pins. They also share the B port with the LEDs, thus it is necessary to disable the LEDs when displaying numbers on the digits. Each digit has to be lit one at a time and cycled very fast to give the impression that they are all lit at once. The code has to run fast enough or else it will look strange (the LEDs will appear to flicker). An issue that caused the program to run slowly was the necessity to add a delay to debounce the switches, and a shorter delay when sending commands to the LCD screen driver, since it does not run as fast as the main HCS12 CPU. Whenever the program entered a delay, I turned off the 7-segment display so it would not flicker or look erratic. The code worked correctly from the beginning, but it took many hours of debugging to prevent the 7-segment display from flickering.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement