How to resolve the algorithm Show ASCII table step by step in the 6502 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Show ASCII table step by step in the 6502 Assembly programming language
Table of Contents
Problem Statement
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Show ASCII table step by step in the 6502 Assembly programming language
Source code in the 6502 programming language
==========================================================================
; task : show ascii table
; language: 6502 Assembly
; for: : rosettacode.org
; run : on a Commodore 64 with command
; sys 49152
;
; same logic of "Commodore BASIC"
;
; assembler win2c64 by Aart Bik
; http://www.aartbik.com/
;
; 2020-05-01 alvalongo
;==========================================================================
; constants
cr = 13 ; carriage-return
white = 5 ; color white
; ----------------------------------------------
; memory on zero page
linnum = $14
; ----------------------------------------------
; kernel routines
linstr = $bdcd ; C64 ROM : convert a 16-bit value to string and print on current device (default screen)
chrout = $ffd2 ; C64 ROM kernel: output a character to current device, default screen
; use $fded for Apple 2
;
; ----------------------------------------------
;
.org $c000 ; start at free RAM, on Commodore 64
; ----------------------------------------------
l100 lda #147 ; clear screen
jsr chrout
;
l110 lda #14 ;character set 2, upper/lower case mode
jsr chrout
;
lda #white ; color for characters
jsr chrout
;
l120 lda #
ldx #>msg1
jsr prtmsg
;
l130 lda #
ldx #>msg2
jsr prtmsg
;
l140 lda #cr
jsr chrout
;
l150 lda #0
sta row
;
l160 lda #0
sta column
;
l170 clc
lda row
adc #32
sta ascii
lda column
asl ; times 2, 2
asl ; times 2, 4
asl ; times 2, 8
asl ; times 2, 16
adc ascii
sta ascii
;
l180 cmp #100
bcs l185 ; equal or greater than
lda #" " ; a space before values less than 100
jsr chrout
;
l185 ldx ascii
lda #0
jsr linstr ; convert to string and print on screen
lda #":"
jsr chrout
lda ascii
jsr chrout
lda #" "
jsr chrout
;
l190 inc column ; next column
lda column
cmp #5
bcc l170
beq l170
;
l200 lda #cr
jsr chrout
;
l210 inc row ; next row
lda row
cmp #15
bcc l160
beq l160
;
l220 rts ; return to operating system
; ----------------------------------------------
; print message
;
prtmsg sta linnum
stx linnum+1
ldy #0
l310 lda (linnum),y
beq l320
jsr chrout
iny
bne l310
l320 lda #cr
jsr chrout
rts
; ----------------------------------------------
msg1 .byte "COMMODORE 64 - BASIC V2",0
msg2 .byte "CHARACTER SET 2 UPPER/LOWER CASE MODE",0
row .byte 0
column .byte 0
ascii .byte 0
You may also check:How to resolve the algorithm Monads/Maybe monad step by step in the REXX programming language
You may also check:How to resolve the algorithm Arrays step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Arithmetic derivative step by step in the Raku programming language
You may also check:How to resolve the algorithm URL decoding step by step in the D programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the Java programming language