How to resolve the algorithm Show ASCII table step by step in the ARM Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Show ASCII table step by step in the ARM 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 ARM Assembly programming language
Source code in the arm programming language
.equ CursorX,0x02000000
.equ CursorY,0x02000001
ProgramStart:
mov sp,#0x03000000 ;Init Stack Pointer
mov r4,#0x04000000 ;DISPCNT -LCD Control
mov r2,#0x403 ;4= Layer 2 on / 3= ScreenMode 3
str r2,[r4] ;now the screen is visible
bl ResetTextCursors ;set text cursors to top left of screen
mov r2,#32
mov r3,#32+20 ;screen height is 20 chars
mov r5,#0 ;column spacer
mov r6,#5
;R0 = Character to print (working copy)
;R2 = real copy
;R3 = compare factor
loop_printAscii:
mov r0,r2
bl ShowHex
mov r0,#32
bl PrintChar
mov r0,r2
bl PrintChar
bl CustomNewLine
add r2,r2,#1
cmp r2,#128
beq forever ;exit early
cmp r2,r3
bne loop_printAscii
add r3,r3,#20 ;next section
;inc to next column
add r5,r5,#5
mov r0,r5
mov r1,#0
bl SetTextCursors
subs r6,r6,#1
bne loop_printAscii
forever:
b forever
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; INPUT/OUTPUT SUBROUTINES - CREATED BY KEITH OF CHIBIAKUMAS.COM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString: ;Print 255 terminated string
STMFD sp!,{r0-r12, lr}
PrintStringAgain:
ldrB r0,[r1],#1
cmp r0,#255
beq PrintStringDone ;Repeat until 255
bl printchar ;Print Char
b PrintStringAgain
PrintStringDone:
LDMFD sp!,{r0-r12, pc}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintChar:
STMFD sp!,{r0-r12, lr}
mov r4,#0
mov r5,#0
mov r3,#CursorX
ldrB r4,[r3] ;X pos
mov r3,#CursorY
ldrB r5,[r3] ;Y pos
mov r3,#0x06000000 ;VRAM base
mov r6,#8*2 ;Xpos, 2 bytes per pixel, 8 bytes per char
mul r2,r4,r6
add r3,r3,r2
mov r4,#240*8*2 ;Ypos, 240 pixels per line,
mul r2,r5,r4 ;2 bytes per pixel, 8 lines per char
add r3,r3,r2
adr r4,BitmapFont ;Font source
sub r0,r0,#32 ;First Char is 32 (space)
add r4,r4,r0,asl #3 ;8 bytes per char
mov r1,#8 ;8 lines
DrawLine:
mov r7,#8 ;8 pixels per line
ldrb r8,[r4],#1 ;Load Letter
mov r9,#0b100000000 ;Mask
mov r2, #0b1111111101000000; Color: ABBBBBGGGGGRRRRR A=Alpha
DrawPixel:
tst r8,r9 ;Is bit 1?
strneh r2,[r3] ;Yes? then fill pixel (HalfWord)
add r3,r3,#2
mov r9,r9,ror #1 ;Bitshift Mask
subs r7,r7,#1
bne DrawPixel ;Next Hpixel
add r3,r3,#480-16 ;Move Down a line (240 pixels *2 bytes)
subs r1,r1,#1 ;-1 char (16 px)
bne DrawLine ;Next Vline
LineDone:
mov r3,#CursorX
ldrB r0,[r3]
add r0,r0,#1 ;Move across screen
strB r0,[r3]
mov r10,#30
cmp r0,r10
bleq NewLine
LDMFD sp!,{r0-r12, pc}
NewLine:
STMFD sp!,{r0-r12, lr}
mov r3,#CursorX
mov r0,#0
strB r0,[r3]
mov r4,#CursorY
ldrB r0,[r4]
add r0,r0,#1
strB r0,[r4]
LDMFD sp!,{r0-r12, pc}
CustomNewLine:
STMFD sp!,{r0-r12, lr}
mov r3,#CursorX
mov r0,r5
strB r0,[r3]
mov r4,#CursorY
ldrB r0,[r4]
add r0,r0,#1
strB r0,[r4]
LDMFD sp!,{r0-r12, pc}
ResetTextCursors:
STMFD sp!,{r4-r6,lr}
mov r4,#0
mov r5,#CursorX
mov r6,#CursorY
strB r4,[r5]
strB r4,[r6]
LDMFD sp!,{r4-r6,lr}
bx lr
SetTextCursors:
;input: R0 = new X
; R1 = new Y
STMFD sp!,{r5-r6}
mov r5,#CursorX
mov r6,#CursorY
strB r0,[r5]
strB r1,[r6]
LDMFD sp!,{r5-r6}
bx lr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ShowHex:
STMFD sp!,{r0-r12, lr}
mov r2,r0,ror #4
bl ShowHexChar
mov r2,r0
bl ShowHexChar
LDMFD sp!,{r0-r12, pc}
ShowHexChar:
STMFD sp!,{r0-r12, lr}
;mov r3,
and r0,r2,#0x0F ; r3
cmp r0,#10
addge r0,r0,#7 ;if 10 or greater convert to alphabet letters a-f
add r0,r0,#48
bl PrintChar
LDMFD sp!,{r0-r12, pc}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BitmapFont:
;each byte represents a row of 8 pixels. This is a 1BPP font that is converted to the GBA's 16bpp screen format at runtime
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 20
.byte 0x10,0x18,0x18,0x18,0x18,0x00,0x18,0x00 ; 21
.byte 0x28,0x6C,0x28,0x00,0x00,0x00,0x00,0x00 ; 22
.byte 0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00 ; 23
.byte 0x18,0x3E,0x48,0x3C,0x12,0x7C,0x18,0x00 ; 24
.byte 0x02,0xC4,0xC8,0x10,0x20,0x46,0x86,0x00 ; 25
.byte 0x10,0x28,0x28,0x72,0x94,0x8C,0x72,0x00 ; 26
.byte 0x0C,0x1C,0x30,0x00,0x00,0x00,0x00,0x00 ; 27
.byte 0x18,0x18,0x30,0x30,0x30,0x18,0x18,0x00 ; 28
.byte 0x18,0x18,0x0C,0x0C,0x0C,0x18,0x18,0x00 ; 29
.byte 0x08,0x49,0x2A,0x1C,0x14,0x22,0x41,0x00 ; 2A
.byte 0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00 ; 2B
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30 ; 2C
.byte 0x00,0x00,0x00,0x7E,0x7E,0x00,0x00,0x00 ; 2D
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00 ; 2E
.byte 0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00 ; 2F
.byte 0x7C,0xC6,0xD6,0xD6,0xD6,0xC6,0x7C,0x00 ; 30
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 31
.byte 0x3C,0x7E,0x06,0x3C,0x60,0x7E,0x3C,0x00 ; 32
.byte 0x3C,0x7E,0x06,0x1C,0x06,0x7E,0x3C,0x00 ; 33
.byte 0x18,0x3C,0x64,0xCC,0x7C,0x0C,0x08,0x00 ; 34
.byte 0x3C,0x7E,0x60,0x7C,0x06,0x7E,0x3E,0x00 ; 35
.byte 0x3C,0x7E,0x60,0x7C,0x66,0x66,0x3C,0x00 ; 36
.byte 0x3C,0x7E,0x06,0x0C,0x18,0x18,0x10,0x00 ; 37
.byte 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00 ; 38
.byte 0x3C,0x66,0x66,0x3E,0x06,0x7E,0x3C,0x00 ; 39
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x00 ; 3A
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x30 ; 3B
.byte 0x0C,0x1C,0x38,0x60,0x38,0x1C,0x0C,0x00 ; 3C
.byte 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00 ; 3D
.byte 0x60,0x70,0x38,0x0C,0x38,0x70,0x60,0x00 ; 3E
.byte 0x3C,0x76,0x06,0x1C,0x00,0x18,0x18,0x00 ; 3F
.byte 0x7C,0xCE,0xA6,0xB6,0xC6,0xF0,0x7C,0x00 ; 40 @
.byte 0x18,0x3C,0x66,0x66,0x7E,0x66,0x24,0x00 ; 41 A
.byte 0x3C,0x66,0x66,0x7C,0x66,0x66,0x3C,0x00 ; 42 B
.byte 0x38,0x7C,0xC0,0xC0,0xC0,0x7C,0x38,0x00 ; 43 C
.byte 0x3C,0x64,0x66,0x66,0x66,0x64,0x38,0x00 ; 44 D
.byte 0x3C,0x7E,0x60,0x78,0x60,0x7E,0x3C,0x00 ; 45 E
.byte 0x38,0x7C,0x60,0x78,0x60,0x60,0x20,0x00 ; 46 F
.byte 0x3C,0x66,0xC0,0xC0,0xCC,0x66,0x3C,0x00 ; 47 G
.byte 0x24,0x66,0x66,0x7E,0x66,0x66,0x24,0x00 ; 48 H
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 49 I
.byte 0x08,0x0C,0x0C,0x0C,0x4C,0xFC,0x78,0x00 ; 4A J
.byte 0x24,0x66,0x6C,0x78,0x6C,0x66,0x24,0x00 ; 4B K
.byte 0x20,0x60,0x60,0x60,0x60,0x7E,0x3E,0x00 ; 4C L
.byte 0x44,0xEE,0xFE,0xD6,0xD6,0xD6,0x44,0x00 ; 4D M
.byte 0x44,0xE6,0xF6,0xDE,0xCE,0xC6,0x44,0x00 ; 4E N
.byte 0x38,0x6C,0xC6,0xC6,0xC6,0x6C,0x38,0x00 ; 4F O
.byte 0x38,0x6C,0x64,0x7C,0x60,0x60,0x20,0x00 ; 50 P
.byte 0x38,0x6C,0xC6,0xC6,0xCA,0x74,0x3A,0x00 ; 51 Q
.byte 0x3C,0x66,0x66,0x7C,0x6C,0x66,0x26,0x00 ; 52 R
.byte 0x3C,0x7E,0x60,0x3C,0x06,0x7E,0x3C,0x00 ; 53 S
.byte 0x3C,0x7E,0x18,0x18,0x18,0x18,0x08,0x00 ; 54 T
.byte 0x24,0x66,0x66,0x66,0x66,0x66,0x3C,0x00 ; 55 U
.byte 0x24,0x66,0x66,0x66,0x66,0x3C,0x18,0x00 ; 56 V
.byte 0x44,0xC6,0xD6,0xD6,0xFE,0xEE,0x44,0x00 ; 57 W
.byte 0xC6,0x6C,0x38,0x38,0x6C,0xC6,0x44,0x00 ; 58 X
.byte 0x24,0x66,0x66,0x3C,0x18,0x18,0x08,0x00 ; 59 Y
.byte 0x7C,0xFC,0x0C,0x18,0x30,0x7E,0x7C,0x00 ; 5A Z
.byte 0x1C,0x30,0x30,0x30,0x30,0x30,0x1C,0x00 ; 5B [
.byte 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x00 ; 5C Backslash
.byte 0x38,0x0C,0x0C,0x0C,0x0C,0x0C,0x38,0x00 ; 5D ]
.byte 0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00 ; 5E ^
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C ; 5F _
.byte 0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00 ; 60 `
.byte 0x00,0x00,0x38,0x0C,0x7C,0xCC,0x78,0x00 ; 61
.byte 0x20,0x60,0x7C,0x66,0x66,0x66,0x3C,0x00 ; 62
.byte 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00 ; 63
.byte 0x08,0x0C,0x7C,0xCC,0xCC,0xCC,0x78,0x00 ; 64
.byte 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00 ; 65
.byte 0x1C,0x36,0x30,0x38,0x30,0x30,0x10,0x00 ; 66
.byte 0x00,0x00,0x3C,0x66,0x66,0x3E,0x06,0x3C ; 67
.byte 0x20,0x60,0x6C,0x76,0x66,0x66,0x24,0x00 ; 68
.byte 0x18,0x00,0x18,0x18,0x18,0x18,0x08,0x00 ; 69
.byte 0x06,0x00,0x04,0x06,0x06,0x26,0x66,0x3C ; 6A
.byte 0x20,0x60,0x66,0x6C,0x78,0x6C,0x26,0x00 ; 6B
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 6C
.byte 0x00,0x00,0x6C,0xFE,0xD6,0xD6,0xC6,0x00 ; 6D
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x24,0x00 ; 6E
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00 ; 6F
.byte 0x00,0x00,0x3C,0x66,0x66,0x7C,0x60,0x20 ; 70
.byte 0x00,0x00,0x78,0xCC,0xCC,0x7C,0x0C,0x08 ; 71
.byte 0x00,0x00,0x38,0x7C,0x60,0x60,0x20,0x00 ; 72
.byte 0x00,0x00,0x3C,0x60,0x3C,0x06,0x7C,0x00 ; 73
.byte 0x10,0x30,0x3C,0x30,0x30,0x3E,0x1C,0x00 ; 74
.byte 0x00,0x00,0x24,0x66,0x66,0x66,0x3C,0x00 ; 75
.byte 0x00,0x00,0x24,0x66,0x66,0x3C,0x18,0x00 ; 76
.byte 0x00,0x00,0x44,0xD6,0xD6,0xFE,0x6C,0x00 ; 77
.byte 0x00,0x00,0xC6,0x6C,0x38,0x6C,0xC6,0x00 ; 78
.byte 0x00,0x00,0x24,0x66,0x66,0x3E,0x06,0x7C ; 79
.byte 0x00,0x00,0x7E,0x0C,0x18,0x30,0x7E,0x00 ; 7A
.byte 0x10,0x20,0x20,0x40,0x40,0x20,0x20,0x10 ; 7B {
.byte 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 ; 7C |
.byte 0x08,0x04,0x04,0x02,0x02,0x04,0x04,0x08 ; 7D }
.byte 0x00,0x00,0x00,0x20,0x52,0x0C,0x00,0x00 ; 7E ~
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 7F
.byte 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ; 80
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Forth programming language
You may also check:How to resolve the algorithm Rate counter step by step in the REXX programming language
You may also check:How to resolve the algorithm Day of the week step by step in the Modula-3 programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Mind boggling card trick step by step in the AutoHotkey programming language