.include "labmac.i" .section .text .globl main main: MOVE.L #25, D0 | clear all 26 counters (25..0) clear: CLR.L (array,D0.L*4) | use D0 as index DBF D0, clear | decrement and branch until -1 LEA text, A5 | load start address CLR.L D0 proc: MOVE.B (A5)+, D0 | read text one character at a time BEQ done | NULL char terminates input string CMP2.B lower, D0 | check whether lower <= D0 <= upper BCS proc | branch if out-of-bounds SUB.B lower,D0 ADD.L #1,(array,D0.L*4) | increment corresponding counter JMP proc done: LEA array,A5 MOVE.L #'A', D5 | print all 26 counters out: MOVE.L D5, D1 | print current letter CALLEXEC LCD_PutChar MOVE.L (A5)+,D1 | load counter in D1 JSR outint | print integer ADD.L #1, D5 | increment to next letter CMP.B #'Z', D5 | check if last letter BLE out | do for all counters RTS array: DS.L 26 | array of counters lower: DC.B 'A' | lower + upper bounds upper: DC.B 'Z' | text to be analyzed text: .asciz "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG." | ---------------------------------------------- .even outint: MOVEM.L D1-D2/A0,-(SP) | SAVE REGISTERS MOVE.L #intstr+10, A0 | pointer A0 behind last digit loop: DIVUL.L #10, D2:D1 | D1 := D1/10, D2 := remainder ADD.B #'0', D2 | make D2 digit character MOVE.B D2, -(A0) | write digit TST.L D1 | check quotient BNE loop | while # 0 repeat quotient in D1 print: CALLEXEC LCD_PutString | call string print (address in A0) MOVEM.L (SP)+,D1-D2/A0 | RESTORE REGISTERS RTS intstr: .asciz "1234567890 " | number can have up to 10 digits