unsplash-image-pfR18JNEMv8.jpg

Assembly Language - Grades Tally

Grades Tally - Assembly Language


 This assembly language program is written for Motorola 68HC12 microcontroller in AsmIDE.

This program counts how many letter grades for each letter are present from an memory address defined in an external text file. I use branch instructions to loop through each memory address and compare each letter grade and tally them accordingly in a specific memory address. Memory addresses $103A tallies each ‘A’ grade, $103B each ‘B’, $103C each ‘C’, $103D each ‘D’ and $103F each ‘F’. The result can be seen in a simulator as recorded below.

A video demonstrating the output and the code is shown below:

Source Code

Program
Grades File
Exported from Notepad++
1 ; GradesII.asm 2 ; 3 ; Author: Mostapha Abdelaziz 4 ; Course: CST8216 Processor Architecture 5 ; 6 ; Purpose: To Tally up the number of As, Bs, Cs, Ds and Fs 7 ; in a Grades Array as per 21S Flowchart for GradesII 8 ; which uses a Switch-Case approach. 9 10 ; 11 org $1020 12 Grades 13 #include Grades.txt ; Grades file supplied for assignment 14 End_Grades 15 16 ; Expected Result 17 18 ; $103A $103B $103C $103D $103E $103F 19 ; 5 3 2 3 N/A 3 20 21 ; as shown in the sumulator 22 23 org $103A ; storage for counting grades start here 24 Storage ds 6 25 26 org $2000 27 lds #$2000 ; Stack initialization 28 29 ; load pointers for beginning of grades array, and storage for counting 30 ldx #Grades 31 ldy #Storage 32 33 ; Read grade and start of loop 34 A ldaa 1,x+ ; load acc a with beginning array, incrementing each loop 35 36 ; compare the indexed array value to count each letter grade 37 CheckF cmpa #'F' 38 beq AsgnF 39 CheckD cmpa #'D' ; compare to D 40 beq AsgnD 41 CheckC cmpa #'C' ; compare to C 42 beq AsgnC 43 CheckB cmpa #'B' ; compare to B 44 beq AsgnB 45 CheckA cmpa #'A' ; compare to A 46 beq AsgnA 47 bra Check 48 49 ; Increment the appropriate memory address depending on grade letter 50 AsgnA ldaa 0,y ; increment address for letter grade A 51 inca 52 staa 0,y 53 bra Check 54 AsgnB ldaa 1,y ; increment address for letter grade B 55 inca 56 staa 1,y 57 bra Check 58 AsgnC ldaa 2,y ; increment address for letter grade C 59 inca 60 staa 2,y 61 bra Check 62 AsgnD ldaa 3,y ; increment address for letter grade D 63 inca 64 staa 3,y 65 bra Check 66 AsgnF ldaa 5,y ; increment address for letter grade F 67 inca 68 staa 5,y 69 bra Check 70 71 ; Check if all grades have been processed 72 Check cpx #End_Grades 73 bne A ; compare incremented array pointer to end grades 74 ; if it is not equal, loop otherwise end program 75 76 swi ; forces program to quit executing in memory 77 end ; end the program 78
Exported from Notepad++
1 db 'F, 'B, 'A, 'D, 'B 2 db 'A, 'B, 'C, 'A, 'C 3 db 'D, 'A, 'F 4 db 'A, 'F, 'D