Page 189 - ARM 64 Bit Assembly Language
P. 189
176 Chapter 6
28 mov x19, x1 // save address of node
29
30 // ptrs = getptrs(ptrs, node->left)
31 ldr x1, [x19, #wln_left]
32 bl getptrs
33
34 // *(ptrs++)=node
35 str x19, [x0], #8
36 // return getptrs(ptrs, node->right)
37
38 ldr x1, [x19, #wln_right]
39 bl getptrs
40 ldr x19, [sp, #16]
41 ldp x29, x30, [sp], #32
42 getptrs_exit:
43 ret
44 .size getptrs,(. - getptrs)
45
46 ### ----------------------------------------------------------
47 ### wl_print_numerical prints a table showing the number
48 ### of occurrences for each word, followed by the word,
49 ### sorted in reverse order of occurence.
50 ### void wl_print_numerical(wordlist *list)
51 .type wl_print_numerical, %function
52 .global wl_print_numerical
53 wl_print_numerical:
54 stp x29, x30, [sp, #-48]!
55 stp x19, x20, [sp, #16]
56 str x21, [sp, #32]
57
58 // wordlistnode **ptrs=malloc(list->nwords*sizeof(wordlistnode*));
59 mov x19, x0 // x19 = list
60 ldr w20, [x0, #wl_nwords] // w20 = list->nwords
61 lsl x0, x20, #3 // x0 = list->nwords*8
62 bl malloc // allocate storage
63
64 // check return value
65 cmp x0, #0
66 bne malloc_ok
67 adr x0, failstr // load pointer to string
68 bl printf
69 mov w0, #1
70 ldr x21, [sp, #32]
71 ldp x19, x20, [sp, #16]
72 ldp x29, x30, [sp], #48
73 bl exit // exit(1)
74 malloc_ok:
75
76 // getptrs(ptrs, list->root)