mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-23 07:28:04 +08:00
Added more comments and moved delay value to rodata
This commit is contained in:
parent
b2563648a0
commit
26f59281cb
1 changed files with 18 additions and 7 deletions
|
|
@ -17,22 +17,28 @@
|
||||||
back (-1 to 1)
|
back (-1 to 1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.equ MAX_COLUMN, 60
|
.equ MAX_COLUMN, 60 // These are equivalent to
|
||||||
.equ NUM_CHARS, 4
|
.equ NUM_CHARS, 4 // #define in C and C++
|
||||||
|
|
||||||
counter .req w20
|
counter .req w20 // These also but these are for
|
||||||
delta .req w21
|
delta .req w21 // use with registers
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata // In essence: const
|
||||||
|
|
||||||
CHARS: .asciz "|/_\\"
|
CHARS: .asciz "|/_\\"
|
||||||
TRM: .asciz " \r" // The space is important.
|
TRM: .asciz " \r" // The space is important.
|
||||||
|
usec: .int 75000 // 0.075 seconds delay AT LEAST
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
||||||
main: stp x29, x30, [sp, -16]!
|
main: stp x29, x30, [sp, -16]!
|
||||||
stp counter, delta, [sp, -16]!
|
stp counter, delta, [sp, -16]!
|
||||||
|
|
||||||
|
// counter will move up and down between MAX_COLUMN and 0
|
||||||
|
// by toggling delta from 1 to -1 and back. This is far
|
||||||
|
// simpler than creating dual for loops which one might do
|
||||||
|
// in a naive implementation.
|
||||||
|
|
||||||
mov counter, wzr
|
mov counter, wzr
|
||||||
mov delta, 1
|
mov delta, 1
|
||||||
mov w0, wzr
|
mov w0, wzr
|
||||||
|
|
@ -40,6 +46,8 @@ main: stp x29, x30, [sp, -16]!
|
||||||
0: bl Pad
|
0: bl Pad
|
||||||
bl Emit
|
bl Emit
|
||||||
bl Terminator
|
bl Terminator
|
||||||
|
// Having completed output for this animation cycle, adjust
|
||||||
|
// counter toggling delta if necessary.
|
||||||
add counter, counter, delta
|
add counter, counter, delta
|
||||||
mov w0, MAX_COLUMN
|
mov w0, MAX_COLUMN
|
||||||
cmp w0, counter
|
cmp w0, counter
|
||||||
|
|
@ -49,6 +57,7 @@ main: stp x29, x30, [sp, -16]!
|
||||||
1: cbnz counter, 2f
|
1: cbnz counter, 2f
|
||||||
neg delta, delta
|
neg delta, delta
|
||||||
|
|
||||||
|
// Cause the delay between animation cycles.
|
||||||
2: ldr x0, =usec
|
2: ldr x0, =usec
|
||||||
ldr w0, [x0]
|
ldr w0, [x0]
|
||||||
bl usleep
|
bl usleep
|
||||||
|
|
@ -62,7 +71,8 @@ main: stp x29, x30, [sp, -16]!
|
||||||
ret
|
ret
|
||||||
|
|
||||||
/* Terminator - outputs "\r " - notice the space after
|
/* Terminator - outputs "\r " - notice the space after
|
||||||
the carriage return.
|
the carriage return. It is important. Try redoing this
|
||||||
|
with the space removed to see why.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Terminator:
|
Terminator:
|
||||||
|
|
@ -134,5 +144,6 @@ mod: sdiv x2, x0, x1 // x2 gets a // b
|
||||||
|
|
||||||
.data
|
.data
|
||||||
buff: .space 4
|
buff: .space 4
|
||||||
usec: .int 75000
|
|
||||||
|
.end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue