mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-23 04:46:47 +08:00
added a few lines to snow
This commit is contained in:
parent
96bb9755db
commit
90833b214a
1 changed files with 21 additions and 7 deletions
|
|
@ -17,19 +17,25 @@ main: stp x29, x30, [sp, -16]!
|
||||||
|
|
||||||
// Allocate the storm.
|
// Allocate the storm.
|
||||||
|
|
||||||
mov x0, NUM_FLAKES
|
mov x0, NUM_FLAKES // Calculate space needed.
|
||||||
mov x1, Flake.size
|
mov x1, Flake.size
|
||||||
mul x0, x0, x1
|
mul x0, x0, x1
|
||||||
bl malloc
|
str x0, [sp, -16]! // Save for memset.
|
||||||
cbnz x0, 1f
|
bl malloc // Attempt the allocation.
|
||||||
|
cbnz x0, 1f // Branch if successful.
|
||||||
|
|
||||||
ldr x0, =bad_malloc
|
add sp, sp, 16 // Undo stack change.
|
||||||
|
ldr x0, =bad_malloc // Inform user of tragedy.
|
||||||
bl puts
|
bl puts
|
||||||
mov w0, 1
|
mov w0, 1
|
||||||
b bye
|
b bye
|
||||||
|
|
||||||
1: mov storm, x0
|
1: mov storm, x0 // The base address of the
|
||||||
|
// allocated memory will be
|
||||||
|
// preserved in x27.
|
||||||
|
ldr x2, [sp], 16 // Restore the allocation size.
|
||||||
|
mov w1, xzr // Fill with zero.
|
||||||
|
bl memset // x0 still had base address.
|
||||||
|
|
||||||
99: mov x0, storm
|
99: mov x0, storm
|
||||||
bl free
|
bl free
|
||||||
|
|
@ -40,8 +46,16 @@ bye: ldp x27, x28, [sp], 16
|
||||||
ldp x20, x30, [sp], 16
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* x0 contains the address of a Flake in need of being reset.
|
||||||
|
The column number of a Flake is anywhere from 1 to 80 (a
|
||||||
|
default terminal). The starting line is anywhere from 1 to
|
||||||
|
48 (24 x 2) lines ABOVE the screen. This allows the flakes to
|
||||||
|
drift downward without apparent gaps or bunches.
|
||||||
|
*/
|
||||||
ResetFlake:
|
ResetFlake:
|
||||||
|
stp x20, x30, [sp, -16]!
|
||||||
|
ldp x20, x30, [sp], 16
|
||||||
|
ret
|
||||||
|
|
||||||
.data
|
.data
|
||||||
bad_malloc: .asciz "Allocation of flakes has failed"
|
bad_malloc: .asciz "Allocation of flakes has failed"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue