mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-22 23:26:47 +08:00
correction due to arne
This commit is contained in:
parent
88d0bf495a
commit
6243dc9b49
3 changed files with 29 additions and 5 deletions
|
|
@ -564,13 +564,27 @@ copied. Again, this is a predecrement.
|
||||||
In a higher level language `Line 3` would look like this:
|
In a higher level language `Line 3` would look like this:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
*(--sp) = x21;
|
// Stack grows towards smaller addresses. Traditionally,
|
||||||
*(--sp) = x30;
|
// diagrams of memory place 0 at the top and higher
|
||||||
|
// addresses down below. Hence, the saying that "stack
|
||||||
|
// grows upward towards smaller addresses."
|
||||||
|
*(--sp) = x30; // the 2nd arg of stp goes on the stack 1st
|
||||||
|
*(--sp) = x21; // the 1st arg of stp goes on the stack 2nd
|
||||||
```
|
```
|
||||||
|
|
||||||
That is, subtract 8 from the stack pointer and copy `x21` to that
|
In a diagram the results of `stp x21, x30, [sp, -16]!` looks like this:
|
||||||
location. Then, subtract 8 from the stack pointer and copy `x30` to that
|
|
||||||
location.
|
| address | value |
|
||||||
|
| ------- | ----- |
|
||||||
|
| smaller address | x21 |
|
||||||
|
| larger address | x30 |
|
||||||
|
|
||||||
|
File this information away as it makes understanding
|
||||||
|
[variadics](../../more/varargs/) easier to understand on the Apple M
|
||||||
|
series. Note `variadic` functions are an advanced topic.
|
||||||
|
|
||||||
|
A previous version of this text contained an error. This new version is
|
||||||
|
inspired by `arne` on Github to whome we owe thanks.
|
||||||
|
|
||||||
**The stack pointer in ARM V8 can only be manipulated in multiples of
|
**The stack pointer in ARM V8 can only be manipulated in multiples of
|
||||||
16.**
|
16.**
|
||||||
|
|
|
||||||
Binary file not shown.
10
section_1/hello_world/stack_order.S
Normal file
10
section_1/hello_world/stack_order.S
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
.text
|
||||||
|
.p2align 2
|
||||||
|
.global main
|
||||||
|
|
||||||
|
main: stp xzr, x30, [sp, -16]!
|
||||||
|
ldp xzr, x30, [sp], 16
|
||||||
|
ret
|
||||||
|
|
||||||
|
.end
|
||||||
|
|
||||||
Loading…
Reference in a new issue