From 4a68a6fb02ac4e5ef9a1e0e4b1ef84214b6f8fae Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 3 Nov 2025 12:19:39 +0900 Subject: [PATCH] add L7 and L8 pdf and complement in 1103 --- notes/8.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pdf/L7.pdf | 3 ++ pdf/L8.pdf | 3 ++ 3 files changed, 92 insertions(+) create mode 100644 notes/8.md create mode 100644 pdf/L7.pdf create mode 100644 pdf/L8.pdf diff --git a/notes/8.md b/notes/8.md new file mode 100644 index 0000000..c428ab9 --- /dev/null +++ b/notes/8.md @@ -0,0 +1,86 @@ +# ARM Subroutines + +Subroutine, Function, Procedure + +It has a single-entry and single-exit. + +* `bl lbl` + * set `lr` to the next instruction location + * set `pc` to the label +* `bx lr` + * set `pc` to the saved `lr` + +ARM register calling convention: + + + +Passing Argument via registers: + +```armasm + mov r0, #3 + mov r1, #4 + bl ssq + mov r2, r0 + b endl +SSQ: + mul r0, r0, r0 + mul r1, r1, r1 + add r0, r0, r1 + bx lr +``` + +`pc` **is always incremented by 4**. Each time, 4 bytes are fetched from the instruction memory. It is not depending on instruction size (2 or 4 bytes). + + +## Using Stack + +Stack is a LIFO data structure. +* `push` / `pop` + +There is two stack growth convention: +* Ascending and Descending. +* Full and Empty + +`sp` = `r13` +Coretex-M uses **Full Descending stack**. + +commands +* `push {register_list}` +* `stmdb sp!, {register_list}` +* `pop {register_list}` +* `ldmia sp!, {register_list}` + +**`push` instruction** + +`push {Rd}` + +**`pop` instruction** + + +### multi-level subroutines + +```armasm +main: + mov r0, #2 + bl quad +quad: + push { lr } + bl sq + bl sq + pop { lr } + bx lr +sq: + mul r0, r0 + bx lr +``` + +## Initializing SP + +Before using the stack, software has to define stack pointer + + +## Recursive Function + +No difference to multi-level subroutines. + +It has multiple stack frames. \ No newline at end of file diff --git a/pdf/L7.pdf b/pdf/L7.pdf new file mode 100644 index 0000000..bde771e --- /dev/null +++ b/pdf/L7.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9152f30eeede6e969e858443ed193a8492cdea5187e815888cc7ceb1a34e58d +size 823495 diff --git a/pdf/L8.pdf b/pdf/L8.pdf new file mode 100644 index 0000000..f9b44a4 --- /dev/null +++ b/pdf/L8.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71aba31918f14fad274a8e9b7361526f1a7e0e6bf2a153ba4298ff1811ae4012 +size 1212863