mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-22 17:16:48 +08:00
more
This commit is contained in:
parent
90833b214a
commit
3834b607ab
1 changed files with 42 additions and 1 deletions
|
|
@ -3,6 +3,9 @@
|
||||||
.text
|
.text
|
||||||
|
|
||||||
.equ NUM_FLAKES, 150
|
.equ NUM_FLAKES, 150
|
||||||
|
.equ MAX_COLUMN, 80
|
||||||
|
.equ MAX_LINE, 24
|
||||||
|
.equ MAX_LINE_X2, 48
|
||||||
|
|
||||||
storm .req x27
|
storm .req x27
|
||||||
|
|
||||||
|
|
@ -34,7 +37,7 @@ main: stp x29, x30, [sp, -16]!
|
||||||
// allocated memory will be
|
// allocated memory will be
|
||||||
// preserved in x27.
|
// preserved in x27.
|
||||||
ldr x2, [sp], 16 // Restore the allocation size.
|
ldr x2, [sp], 16 // Restore the allocation size.
|
||||||
mov w1, xzr // Fill with zero.
|
mov w1, wzr // Fill with zero.
|
||||||
bl memset // x0 still had base address.
|
bl memset // x0 still had base address.
|
||||||
|
|
||||||
99: mov x0, storm
|
99: mov x0, storm
|
||||||
|
|
@ -54,9 +57,47 @@ bye: ldp x27, x28, [sp], 16
|
||||||
*/
|
*/
|
||||||
ResetFlake:
|
ResetFlake:
|
||||||
stp x20, x30, [sp, -16]!
|
stp x20, x30, [sp, -16]!
|
||||||
|
mov x20, x0
|
||||||
|
|
||||||
|
// Initialize Column --- 1 <= random value <= 80
|
||||||
|
bl rand
|
||||||
|
mov x1, MAX_COLUMN
|
||||||
|
bl mod
|
||||||
|
add w1, w1, 1
|
||||||
|
str w1, [x20, 4]
|
||||||
|
|
||||||
|
// Initialize Line --- -(1 <= random value <= 48)
|
||||||
|
|
||||||
|
bl rand
|
||||||
|
mov x1, MAX_LINE_X2
|
||||||
|
bl mod
|
||||||
|
add w1, w1, 1
|
||||||
|
neg w1, w1
|
||||||
|
str w1, [x20]
|
||||||
|
|
||||||
ldp x20, x30, [sp], 16
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* mod(a, b) - implements a % b - AARCH64 lacks a mod instruction.
|
||||||
|
A strange place to economize, but there you have it.
|
||||||
|
|
||||||
|
a comes to us in x0
|
||||||
|
b comes to us in x1
|
||||||
|
|
||||||
|
method:
|
||||||
|
* integer divide a by b
|
||||||
|
for example - 5 % 3 would need 5 // 3 yielding 1
|
||||||
|
* multiply result by b
|
||||||
|
1 * 3 is 3
|
||||||
|
* subtract result from a
|
||||||
|
5 - 3 is 2 and that's our return value.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mod: sdiv x2, x0, x1 // x2 gets a // b
|
||||||
|
msub x0, x2, x1, x0 // x0 gets a - a // b * b
|
||||||
|
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