* Standard equates CODE EQU $E000 ; Start code in EEPROM DATA EQU $0000 ; Start data in page 0 internal RAM STACK EQU $7FFF ; Start stack at top of external RAM. EOS EQU $FF ; We’ll use hex $FF to mark end-of-string of BCD bytes. ORG DATA ; Begin data segment. array FCB $01,$23,$45,$67,$89,EOS ; Array of packed BCD bytes result RMB 10 ; We'll put the result here ORG CODE ; Begin code segment. Main: LDS #STACK ; Load stack pointer LDX #array ; Load address of data array LDY #result ; Ditto for result array Loop: LDAA 0,X ; Get byte to convert CMPA #EOS ; Compare byte with end of string BEQ Done ; If end of string, then stop JSR BCD2ASC ; Call subroutine to do conversion STD 0,Y ; Store D in result array INX ; Go to the next input byte INY ; Go to next output word INY BRA Loop ; Do it all again Done: WAI ; End of main program, wait for interrupts Infloop: BRA Infloop ; If we ever get here, stay here ************************* * Subroutine Name: Bcd2Asc * Input parameter list: A * Output parameter list: A,B **************************** * This routine converts a Packed BCD byte in A * into a pair of ASCII characters in A,B. ************************************************** LOWER EQU $0F ; Mask for low nybble UPPER EQU $F0 ; Mask for high nybble ASCII EQU $30 ; ASCII code for numeral 0 Bcd2Asc: TAB ; Copy A register to B ANDB #LOWER ; Mask lower nybble of B ADDB #ASCII ; Convert B to ASCII code ANDA #UPPER ; Mask upper nybble of A LSRA ; Logical shift right 4 positions LSRA LSRA LSRA ADDA #ASCII ; Convert A to ASCII RTS ; Return result in A,B