Course Number: ECE-5590ES/ E&C-ENGR 429
Laboratory: Bubble Sort
Date: 04/08/2013
Due Date: 04/15/2013
Student Number: 16146570
Student Name: Vinay Vasanth
OBJECTIVE: The objective of the lab session is to write an assembly level language program to sort an array of decimal numbers in ascending order.
EQUIPMENTS AND SOFTWARE PACKAGES:
PC, PCB with HCS12 Microcontroller and MINI IDE software.
THEORY:
HCS12 microcontroller is an 8bit microcontroller, manufactured by Free scale Semiconductors. It has three 8bit registers (A, B, CCR) and four 16bit pointers(X, Y, SP, PC).
A bubble sort algorithm loops through a set of data items. Comparing items and switching them if they are in the wrong order. This process is repeated until the list is sorted. It is called a bubble sort because the smaller items “bubble up” towards the top of the list.
PROCEDURE: 1. Open the mini IDE software.
2. Type the ALP in the mini IDE text editor or in the Note pad and Load the ALP.
3. Turn on the board by connecting +5v power supply and ground terminal.
4. Build the Program using build option and check for any errors (correct if any) (this step generates a source file with extension .s19).
5. Now load the program using the Load instruction and download option available in the dropdown menu in terminal command.
6. Now verify the result by noting the values in different memory locations and comparing it with the expected result.
7. Finish.
Program:
ORG $0900
ARRAY: DC.B 7,6,1,3,9,1,8,2,4,3,5
COUNT1: EQU $0871
COUNT2: EQU $0872
ORG $0800
LDAA #10
STAA COUNT2
BACK: LDX #$0900
LDY #$0901
LDAA #10
STAA COUNT1
CLRA
AGAIN: LDAA 0, X
CMPA 0,Y
BCC LOOP
INX
INY
DEC COUNT1
BNE AGAIN
DEC COUNT2
BNE BACK
SWI
LOOP: LDAA 0,X
PSHA
PULB
LDAA 0,Y
STAB 0,Y
STAA 0,X
INX
INY
DEC COUNT1
BNE AGAIN
DEC COUNT2
BNE BACK
SWI
Result:
MD 0900
0900 01 01 02 03 03 04 05 06 07 08 09……………
Conclusion: