x86-64 stack.

main
Joshua Potter 2024-10-30 19:29:59 -06:00
parent 472a13c9f3
commit 2d3f5e0879
17 changed files with 451 additions and 482 deletions

View File

@ -215,7 +215,11 @@
"b-tree-initial.png",
"b-tree-inserted-b.png",
"b-tree-inserted-q.png",
"dfs.gif"
"dfs.gif",
"saved-registers.png",
"local-variables.png",
"arg-build-area.png",
"stack-frame.png"
],
"File Hashes": {
"algorithms/index.md": "3ac071354e55242919cc574eb43de6f8",
@ -315,7 +319,7 @@
"combinatorics/additive-principle.md": "d036ac511e382d5c1caca437341a5915",
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
"combinatorics/permutations.md": "d8f81c9e4bf903913aa40bff4851ee71",
"combinatorics/permutations.md": "794822b96aeeadcb31e763f52ffb7b6e",
"combinatorics/combinations.md": "396fc32255710eaf33213efaafdc43d4",
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
@ -391,11 +395,11 @@
"_journal/2024-03/2024-03-15.md": "e54b2513beac5f46313b4c37622adf39",
"_journal/2024-03-17.md": "72e99c7630085aee2c7f340a06b5ada7",
"_journal/2024-03/2024-03-16.md": "ab7629c24ebe70838072cf6acec47cb0",
"encoding/floating-point.md": "90c36f4b93312e28e5cfec3e2a8231f4",
"encoding/floating-point.md": "3331bce1aaf94e0cf5d21d62af386d04",
"_journal/2024-03-18.md": "8479f07f63136a4e16c9cd07dbf2f27f",
"_journal/2024-03/2024-03-17.md": "23f9672f5c93a6de52099b1b86834e8b",
"set/directed-graph.md": "b4b8ad1be634a0a808af125fe8577a53",
"set/index.md": "14daeda39c344ea1d4b8c8eac9fb99b0",
"set/index.md": "29f5f295765101fe11d821faa908b027",
"set/graphs.md": "a56f867f51e69cb7438bbdf6215fca36",
"_journal/2024-03-19.md": "a0807691819725bf44c0262405e97cbb",
"_journal/2024-03/2024-03-18.md": "2c711c50247a9880f7ed0d33b16e1101",
@ -522,7 +526,7 @@
"set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7",
"_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
"_journal/2024-05/2024-05-13.md": "d549dd75fb42b4280d4914781edb0113",
"x86-64/registers.md": "639225864ca4ab67b8cd82d742662fe1",
"x86-64/registers.md": "89a6a1f731c643b6b72ff6a93e895a10",
"_journal/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908",
"_journal/2024-05/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
"_journal/2024-05-16.md": "580c7ec61ec56be92fa8d6affcf0a5f6",
@ -607,7 +611,7 @@
"_journal/2024-06/2024-06-12.md": "f82dfa74d0def8c3179d3d076f94558e",
"_journal/2024-06-14.md": "5d12bc272238ac985a1d35d3d63ea307",
"_journal/2024-06/2024-06-13.md": "e2722a00585d94794a089e8035e05728",
"set/functions.md": "fce911b8610d0d00e39ef7fb8489f240",
"set/functions.md": "7c2522a117917e6f96d2c701deee084d",
"_journal/2024-06-15.md": "92cb8dc5c98e10832fb70c0e3ab3cec4",
"_journal/2024-06/2024-06-14.md": "5d12bc272238ac985a1d35d3d63ea307",
"lambda-calculus/beta-reduction.md": "0935987f2bac0e6298735f2b26fd5885",
@ -784,7 +788,7 @@
"_journal/2024-08/2024-08-21.md": "1637b8ec8475cf3eb4f41d1d86cbf5df",
"_journal/2024-08/2024-08-20.md": "e8bec308d1b29e411c6799ace7ef6571",
"_journal/2024-08-23.md": "3b2feab2cc927e267263cb1e9c173d50",
"set/natural-numbers.md": "3d7dfbf80e38dccccf48f2def485aa80",
"set/natural-numbers.md": "0fb40d1d2f7a0f9976afbacdff1c734b",
"_journal/2024-08-24.md": "563fad24740e44734a87d7c3ec46cec4",
"_journal/2024-08/2024-08-23.md": "7b5a40e83d8f07ff54cd9708017d029c",
"_journal/2024-08/2024-08-22.md": "050235d5dc772b542773743b57ce3afe",
@ -875,7 +879,7 @@
"_journal/2024-10/2024-10-06.md": "65a8e538144f59ee9e7296110cc9aa14",
"_journal/2024-10-09.md": "66acb6c8abbf0c860966223f3299c2bc",
"_journal/2024-10/2024-10-08.md": "2f737d8198b12bf635808964c4887ae1",
"x86-64/procedures.md": "49d733982a9f9ebf2b1bbe419175afca",
"x86-64/procedures.md": "f3241c5d499467d9332d2bb950a97c3d",
"_journal/2024-10-10.md": "29e4be2c164c63f8b7aab56bddee3dd6",
"_journal/2024-10/2024-10-09.md": "b718c6f4cfe3069fcc0faf07ec414f73",
"_journal/2024-10-15.md": "6e696a8d16ba257ed89e8564b771d290",
@ -897,7 +901,14 @@
"_journal/2024-10-23.md": "51b2ca6edf23b6a64fd7d3638a0b54cb",
"_journal/2024-10/2024-10-22.md": "5ff4eb7eba58e77c4fb65b7162a485e6",
"_journal/2024-10-24.md": "33ad9c1d21222b4002fb3760f88800a8",
"_journal/2024-10/2024-10-23.md": "919e5b7773f496f89bb9f1b45a99da7b"
"_journal/2024-10/2024-10-23.md": "919e5b7773f496f89bb9f1b45a99da7b",
"_journal/2024-10-28.md": "242d982565f5f41b084d0ae1737ed923",
"_journal/2024-10/2024-10-27.md": "cba851f3ca4482b776b339b792c4c901",
"_journal/2024-10/2024-10-26.md": "e69e361f941c181828c87368b18d1a1c",
"_journal/2024-10/2024-10-25.md": "0597575213a2bb0e15052efa9404dd1b",
"_journal/2024-10/2024-10-24.md": "4493c339209fdd910866d126b8ebe3c6",
"_journal/2024-10-29.md": "19444fb3b9bef82b200c77a6acc33637",
"_journal/2024-10/2024-10-28.md": "95bcec30eda031bf6410ff51a61b0ee3"
},
"fields_dict": {
"Basic": [

View File

@ -0,0 +1,9 @@
---
title: "2024-10-30"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)

View File

@ -6,4 +6,6 @@ title: 2024-10-27
- [ ] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
- [ ] Korean (Read 1 Story)
* Finished reading "The Silent Patient" by Alex Michaelides.

View File

@ -0,0 +1,12 @@
---
title: "2024-10-28"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
* Notes on [[natural-numbers#Ordering|ordering]] of $\omega$.
* More notes on x86 procedure calls.

View File

@ -0,0 +1,9 @@
---
title: "2024-10-29"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)

View File

@ -271,7 +271,7 @@ END%%
%%ANKI
Basic
What is the next lexicographic ordering of `[ 4 3 2 1 ]`?
Back: N/A
Back: N/A.
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
<!--ID: 1709756610357-->
END%%

View File

@ -1318,7 +1318,7 @@ END%%
%%ANKI
Basic
Let $f$ be a special floating-point value. What is its additive inverse?
Back: N/A
Back: N/A.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1710680824822-->
END%%

View File

@ -1904,7 +1904,7 @@ END%%
%%ANKI
Basic
Let $C_*$ be the closure of $A$ under $f$ defined in terms of function $h$. What is $h$'s codomain?
Back: Assume $f$ maps $B$ into $B$, Then $h$'s codomain is $B$.
Back: Assume $A \subseteq B$ and $f \colon B \rightarrow B$. Then $h$'s codomain is $B$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1729684379373-->
END%%

View File

@ -928,7 +928,7 @@ END%%
%%ANKI
Basic
What is a trivial cycle of (say) graph $G$?
Back: A cycle of length $0$.
Back: A cycle of length $0$, i.e. a single vertex.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1723992830003-->
END%%

View File

@ -1061,6 +1061,14 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre
<!--ID: 1723925562044-->
END%%
%%ANKI
Basic
Let $A, B$ be sets. How is $A \subset B$ defined in FOL?
Back: $A \subset B \Leftrightarrow A \subseteq B \land A \neq B$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488855-->
END%%
## Axiom of Choice
This axiom assumes the existence of some choice function capable of selecting some element from a nonempty set. Note this axiom is controversial because it is non-constructive: there is no procedure we can follow to decide which element was chosen.

View File

@ -1305,6 +1305,72 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre
<!--ID: 1729804914204-->
END%%
## Ordering
For natural numbers $m$ and $n$, define $m$ to be **less than $n$** if and only if $m \in n$. It follows $m \in n \Leftrightarrow m^+ \in n^+$.
%%ANKI
Basic
Let $m, n \in \omega$. How does Enderton prefer denoting $m$ is less than $n$?
Back: As $m \in n$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488824-->
END%%
%%ANKI
Basic
Let $m, n \in \omega$. What dual meaning does Enderton give $m \in n$?
Back: Set membership and ordering.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488827-->
END%%
%%ANKI
Basic
Let $m, n \in \omega$. How does Enderton prefer denoting $m$ is less than or equal to $n$?
Back: As $m \underline\in n$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488830-->
END%%
%%ANKI
Basic
Let $m, n \in \omega$. How is $m \underline\in n$ defined?
Back: As $m \in n \lor m = n$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488833-->
END%%
%%ANKI
Basic
Let $m, n \in \omega$. How is $m = n \lor m \in n$ more compactly denoted?
Back: As $m \underline\in n$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488837-->
END%%
%%ANKI
Cloze
Let $m, n \in \omega$. $m$ {$\in$} $n^+ \Leftrightarrow m$ {$\underline\in$} $n$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488842-->
END%%
%%ANKI
Cloze
Let $m, n \in \omega$. $m$ {$\in$} $n \Leftrightarrow m^+$ {$\in$} $n^+$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488846-->
END%%
%%ANKI
Basic
What does the trichotomy law for $\omega$ state?
Back: For any $m, n \in \omega$ exactly one of $m \in n$, $m = n$, or $n \in m$ holds.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1730118488850-->
END%%
## Bibliography
* Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -98,7 +98,43 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1728481058966-->
END%%
## Control Transfer
%%ANKI
Basic
`Q` is about to call another procedure. What is the highlighted portion of its stack frame for?
![[saved-registers.png]]
Back: Callee-saved registers.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604350-->
END%%
%%ANKI
Basic
`Q` is about to call another procedure. What is the highlighted portion of its stack frame for?
![[local-variables.png]]
Back: Local variables.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604358-->
END%%
%%ANKI
Basic
`Q` is about to call another procedure. What is the highlighted portion of its stack frame for?
![[arg-build-area.png]]
Back: Additional integral arguments.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604401-->
END%%
%%ANKI
Basic
What must still be added to the stack before `Q` passes control to another procedure?
![[stack-frame.png]]
Back: The return address.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604407-->
END%%
## CALL and RET
Like [[conditions#JMP|JMP]] instructions, `call` allows specifying a direct or indirect operand. `call` pushes the address of the instruction following it onto the stack and updates the PC to the operand. `ret` reverts these steps.
@ -189,11 +225,218 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1728559336760-->
END%%
## Data Transfer
## Local Storage
The 6 registers used for passing integral arguments are highlighted [[registers#Integral Arguments|here]]. If more than 6 integral arguments are specified to a procedure, the surplus are placed onto the stack in the caller's frame.
### On the Stack
The 7th argument is placed closer to the top of the stack (i.e. with lower address) than subsequent arguments.
x86-64 employs 6 registers for passing integral (i.e. integer and pointer) arguments between caller and callee.
| Bits | Arg 1 | Arg2 | Arg3 | Arg4 | Arg5 | Arg6 |
| ---- | ------ | ------ | ------ | ------ | ------ | ------ |
| 64 | `%rdi` | `%rsi` | `%rdx` | `%rcx` | `%r8` | `%r9` |
| 32 | `%edi` | `%esi` | `%edx` | `%ecx` | `%r8d` | `%r9d` |
| 16 | `%di` | `%si` | `%dx` | `%cx` | `%r8w` | `%r9w` |
| 8 | `%dil` | `%sil` | `%dl` | `%cl` | `%r8b` | `%r9b` |
If more than 6 integral arguments are specified to a procedure, the surplus are placed onto the stack in the caller's frame. The 7th argument is placed closer to the top of the stack (i.e. with lower address) than subsequent arguments.
%%ANKI
Basic
How many registers are available for passing integral arguments between procedures?
Back: `6`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336766-->
END%%
%%ANKI
Cloze
By convention, register {`%rdi`} is used for {the first integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336787-->
END%%
%%ANKI
Basic
Which register should the first integral argument of a procedure be placed in?
Back: `%rdi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336817-->
END%%
%%ANKI
Cloze
By convention, register {`%rsi`} is used for {the second integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336847-->
END%%
%%ANKI
Basic
Which register should the second integral argument of a procedure be placed in?
Back: `%rsi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336872-->
END%%
%%ANKI
Basic
From smallest to largest, list the four "second integral argument" registers.
Back: `%sil`, `%si`, `%esi`, and `%rsi`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730120342193-->
END%%
%%ANKI
Cloze
{1:`%rdi`} is to the {2:first} integral argument whereas {2:`%rsi`} is to the {1:second} integral argument.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336879-->
END%%
%%ANKI
Cloze
By convention, register {`%rdx`} is used for {the third integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668338-->
END%%
%%ANKI
Basic
Which register should the third integral argument of a procedure be placed in?
Back: `%rdx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668358-->
END%%
%%ANKI
Cloze
By convention, register {`%rcx`} is used for {the fourth integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729193-->
END%%
%%ANKI
Basic
Which register should the fourth integral argument of a procedure be placed in?
Back: `%rcx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729214-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `1`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rdi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820710-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `2`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rsi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820713-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `3`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rdx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820715-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `4`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rcx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820718-->
END%%
%%ANKI
Basic
Let $S$ denote `%rsp` before pushing parameter `int a` onto the stack. What is `%rsp` now?
Back: $S - 8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064915-->
END%%
%%ANKI
Basic
Let $S$ denote `%rsp` before pushing parameter `short a` onto the stack. What is `%rsp` now?
Back: $S - 8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064921-->
END%%
%%ANKI
Basic
Let $S$ denote `%rsp` before pushing parameter `bool a` onto the stack. What is `%rsp` now?
Back: $S - 8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064924-->
END%%
%%ANKI
Basic
After calling `Q`, how much space do local parameters occupy in `P`'s stack frame?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: 0 bytes.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064928-->
END%%
%%ANKI
Basic
After calling `Q`, how much space do local parameters occupy in `P`'s stack frame?
```c
void P() {
Q(1, 2, 3, 4, 5, 6, 7, 8);
}
```
Back: 16 bytes.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064931-->
END%%
%%ANKI
Basic
After calling `Q`, how much space do local parameters occupy in `P`'s stack frame?
```c
void P() {
Q(1, 2, 3, 4, 5, 6, true, 8);
}
```
Back: 16 bytes.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730119064934-->
END%%
%%ANKI
Basic
@ -382,6 +625,72 @@ Tags: c17
<!--ID: 1729811536743-->
END%%
%%ANKI
Basic
Which registers are designated for argument passing?
Back: `%rdi`, `%rsi`, `%rdx`, `%rcx`, and `%r8-%r9`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730120207052-->
END%%
### In Registers
x86-64 employs 6 registers as callee-saved registers. If procedure `P` calls procedure `Q`, `Q` *must* preserve the values of these registers. That is, if `Q` were to modify these registers, `Q` is also responsible for restoring these values before returning back to `P`.
| Bits | | | | | | |
| ---- | ------ | ------ | ------- | ------- | ------- | ------- |
| 64 | `%rbx` | `%rbp` | `%r12` | `%r13` | `%r14` | `%r15` |
| 32 | `%ebx` | `%ebp` | `%r12d` | `%r13d` | `%r14d` | `%r15d` |
| 16 | `%bx` | `%bp` | `%r12w` | `%r13w` | `%r14w` | `%r15w` |
| 8 | `%bl` | `%bpl` | `%r12b` | `%r13b` | `%r14b` | `%15b` |
%%ANKI
Basic
Which registers are designated as callee-saved?
Back: `%rbx`, `%rbp`, and `%r12-%r15`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730120207058-->
END%%
%%ANKI
Basic
How many registers are designated as callee-saved?
Back: 6.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604414-->
END%%
%%ANKI
Basic
*What* is a callee-saved register?
Back: A register whose value must be preserved by a callee on return.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730120207062-->
END%%
%%ANKI
Cloze
By convention, register `%rbp` is used for {callee-saved values}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604421-->
END%%
%%ANKI
Basic
Suppose `P` calls `Q`. Callee-saved registers are in which stack frame?
Back: `Q`'s.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604427-->
END%%
%%ANKI
Basic
Suppose `P` calls `Q` with 8 integral arguments. Which of `P`'s callee-saved values or arguments to `Q` are nearer the stack's top?
Back: `P`'s arguments to `Q`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730121604434-->
END%%
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.

View File

@ -51,6 +51,13 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1713212889864-->
END%%
%%ANKI
Cloze
The x86 8-bit registers all end with suffix {1:`l`} or {1:`b`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1730120615447-->
END%%
%%ANKI
Basic
Instructions that generate 1-byte quantities do what to the remaining bytes of a register?
@ -300,470 +307,6 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1728558297568-->
END%%
## Integral Arguments
x86-64 employs 6 registers for passing integral (i.e. integer and pointer) arguments between caller and callee.
| Bits | Arg 1 | Arg2 | Arg3 | Arg4 | Arg5 | Arg6 |
| ---- | ------ | ------ | ------ | ------ | ------ | ------ |
| 64 | `%rdi` | `%rsi` | `%rdx` | `%rcx` | `%r8` | `%r9` |
| 32 | `%edi` | `%esi` | `%edx` | `%ecx` | `%r8d` | `%r9d` |
| 16 | `%di` | `%si` | `%dx` | `%cx` | `%r8w` | `%r9w` |
| 8 | `%dil` | `%sil` | `%dl` | `%cl` | `%r8b` | `%r9b` |
%%ANKI
Basic
How many registers are available for passing integral arguments between procedures?
Back: `6`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336766-->
END%%
%%ANKI
Basic
How many bytes make up the `%rdi` register?
Back: $8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336770-->
END%%
%%ANKI
Basic
How many bytes make up the `%di` register?
Back: $2$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336774-->
END%%
%%ANKI
Basic
How many bytes make up the `%dil` register?
Back: $1$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336779-->
END%%
%%ANKI
Basic
How many bytes make up the `%edi` register?
Back: $4$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336782-->
END%%
%%ANKI
Cloze
By convention, register {`%rdi`} is used for {the first integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336787-->
END%%
%%ANKI
Cloze
{1:Words} are to {2:`%di`} whereas {2:double words} are to {1:`%edi`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336792-->
END%%
%%ANKI
Cloze
{1:Bytes} are to {2:`%dil`} whereas {2:quad words} are to {1:`%rdi`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336797-->
END%%
%%ANKI
Basic
How do you access the low-order 2 bytes of `%rdi`?
Back: By using `%di`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336802-->
END%%
%%ANKI
Basic
How do you access the low-order 4 bytes of `%rdi`?
Back: By using `%edi`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336808-->
END%%
%%ANKI
Basic
How do you access the low-order byte of `%rdi`?
Back: By using `%dil`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336813-->
END%%
%%ANKI
Basic
Which register should the first integral argument of a procedure be placed in?
Back: `%rdi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336817-->
END%%
%%ANKI
Basic
From smallest to largest, list the four "first integral argument" registers.
Back: `%dil`, `%di`, `%edi`, and `%rdi`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336823-->
END%%
%%ANKI
Basic
How many bytes make up the `%rsi` register?
Back: $8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336829-->
END%%
%%ANKI
Basic
How many bytes make up the `%si` register?
Back: $2$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336834-->
END%%
%%ANKI
Basic
How many bytes make up the `%sil` register?
Back: $1$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336838-->
END%%
%%ANKI
Basic
How many bytes make up the `%esi` register?
Back: $4$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336843-->
END%%
%%ANKI
Cloze
By convention, register {`%rsi`} is used for {the second integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336847-->
END%%
%%ANKI
Cloze
{1:Words} are to {2:`%si`} whereas {2:double words} are to {1:`%esi`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336852-->
END%%
%%ANKI
Cloze
{1:Bytes} are to {2:`%sil`} whereas {2:quad words} are to {1:`%rsi`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336856-->
END%%
%%ANKI
Basic
How do you access the low-order 2 bytes of `%rsi`?
Back: By using `%si`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336860-->
END%%
%%ANKI
Basic
How do you access the low-order 4 bytes of `%rsi`?
Back: By using `%esi`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336864-->
END%%
%%ANKI
Basic
How do you access the low-order byte of `%rsi`?
Back: By using `%sil`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336868-->
END%%
%%ANKI
Basic
Which register should the second integral argument of a procedure be placed in?
Back: `%rsi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336872-->
END%%
%%ANKI
Basic
From smallest to largest, list the four "second integral argument" registers.
Back: `%sil`, `%si`, `%esi`, and `%rsi`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336876-->
END%%
%%ANKI
Cloze
{1:`%rdi`} is to the {2:first} integral argument whereas {2:`%rsi`} is to the {1:second} integral argument.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1728559336879-->
END%%
%%ANKI
Basic
How many bytes make up the `%rdx` register?
Back: $8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668317-->
END%%
%%ANKI
Basic
How many bytes make up the `%dx` register?
Back: $2$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668324-->
END%%
%%ANKI
Basic
How many bytes make up the `%dl` register?
Back: $1$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668328-->
END%%
%%ANKI
Basic
How many bytes make up the `%edx` register?
Back: $4$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668334-->
END%%
%%ANKI
Cloze
By convention, register {`%rdx`} is used for {the third integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668338-->
END%%
%%ANKI
Cloze
{1:Words} are to {2:`%dx`} whereas {2:double words} are to {1:`%edx`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668341-->
END%%
%%ANKI
Cloze
{1:Bytes} are to {2:`%dl`} whereas {2:quad words} are to {1:`%rdx`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668345-->
END%%
%%ANKI
Basic
How do you access the low-order 2 bytes of `%rdx`?
Back: By using `%dx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729174-->
END%%
%%ANKI
Basic
How do you access the low-order 4 bytes of `%rdx`?
Back: By using `%edx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668349-->
END%%
%%ANKI
Basic
How do you access the low-order byte of `%rdx`?
Back: By using `%dl`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668352-->
END%%
%%ANKI
Basic
Which register should the third integral argument of a procedure be placed in?
Back: `%rdx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668358-->
END%%
%%ANKI
Basic
From smallest to largest, list the four "third integral argument" registers.
Back: `%dl`, `%dx`, `%edx`, and `%rdx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729533668361-->
END%%
%%ANKI
Cloze
{1:`%dil`} is to the {2:first} integral argument whereas {2:`%dl`} is to the {1:third} integral argument.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729612004982-->
END%%
%%ANKI
Basic
How many bytes make up the `%rcx` register?
Back: $8$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729180-->
END%%
%%ANKI
Basic
How many bytes make up the `%ecx` register?
Back: $4$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729183-->
END%%
%%ANKI
Basic
How many bytes make up the `%cx` register?
Back: $2$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729186-->
END%%
%%ANKI
Basic
How many bytes make up the `%cl` register?
Back: $1$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729189-->
END%%
%%ANKI
Cloze
By convention, register {`%rcx`} is used for {the fourth integral argument}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729193-->
END%%
%%ANKI
Cloze
{1:Words} are to {2:`%cx`} whereas {2:quad words} are to {1:`%rcx`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729196-->
END%%
%%ANKI
Cloze
{1:Bytes} are to {2:`%cl`} whereas {2:double words} are to {1:`%ecx`}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729200-->
END%%
%%ANKI
Basic
How do you access the low-order 2 bytes of `%rcx`?
Back: By using `%cx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729203-->
END%%
%%ANKI
Basic
How do you access the low-order 4 bytes of `%rcx`?
Back: By using `%ecx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729207-->
END%%
%%ANKI
Basic
How do you access the low-order byte of `%rcx`?
Back: By using `%cl`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729210-->
END%%
%%ANKI
Basic
Which register should the fourth integral argument of a procedure be placed in?
Back: `%rcx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729214-->
END%%
%%ANKI
Basic
From smallest to largest, list the four "fourth integral argument" registers.
Back: `%cl`, `%cx`, `%ecx`, and `%rcx`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729217-->
END%%
%%ANKI
Cloze
{1:`%di`} is to the {2:first} integral argument whereas {2:`%cx`} is to the {1:fourth} integral argument.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729641729221-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `1`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rdi`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820710-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `2`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rci`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820713-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `3`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rdx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820715-->
END%%
%%ANKI
Basic
Which register should `Q` use to access value `4`?
```c
void P() {
Q(1, 2, 3, 4, 5, 6);
}
```
Back: `%rcx`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1729810820718-->
END%%
## Condition Codes
The CPU also maintains a set of single-bit **condition code** registers describing attributes of the most recent arithmetic or logical operation.