From 044b58e0c6a48356eacae9cfc25ccaf0b1b54272 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sun, 9 Jun 2024 07:58:36 -0600 Subject: [PATCH] Condition code registers. --- .../plugins/obsidian-to-anki-plugin/data.json | 31 +- notes/_journal/2024-05/2024-05-29.md | 2 +- notes/_journal/2024-06-09.md | 11 + notes/_journal/2024-06/2024-06-03.md | 2 +- notes/_journal/{ => 2024-06}/2024-06-06.md | 3 +- notes/_journal/2024-06/2024-06-07.md | 9 + notes/_journal/2024-06/2024-06-08.md | 13 + notes/algorithms/order-growth.md | 6 +- notes/c17/strings.md | 4 +- notes/lambda-calculus/alpha-conversion.md | 318 +++++ .../index.md} | 43 +- notes/logic/prop-logic.md | 100 +- notes/programming/pred-trans.md | 8 - notes/x86-64/instructions.md | 1195 ----------------- notes/x86-64/instructions/access.md | 407 ++++++ notes/x86-64/instructions/arithmetic.md | 413 ++++++ notes/x86-64/instructions/condition-codes.md | 97 ++ notes/x86-64/instructions/index.md | 287 ++++ notes/x86-64/instructions/logical.md | 129 ++ notes/x86-64/registers.md | 182 ++- 20 files changed, 1992 insertions(+), 1268 deletions(-) create mode 100644 notes/_journal/2024-06-09.md rename notes/_journal/{ => 2024-06}/2024-06-06.md (57%) create mode 100644 notes/_journal/2024-06/2024-06-07.md create mode 100644 notes/_journal/2024-06/2024-06-08.md create mode 100644 notes/lambda-calculus/alpha-conversion.md rename notes/{programming/lambda-calculus.md => lambda-calculus/index.md} (96%) delete mode 100644 notes/x86-64/instructions.md create mode 100644 notes/x86-64/instructions/access.md create mode 100644 notes/x86-64/instructions/arithmetic.md create mode 100644 notes/x86-64/instructions/condition-codes.md create mode 100644 notes/x86-64/instructions/index.md create mode 100644 notes/x86-64/instructions/logical.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index c585a60..efb2ae0 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -178,7 +178,7 @@ "algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2", "algorithms/loop-invariant.md": "3b390e720f3b2a98e611b49a0bb1f5a9", "algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65", - "algorithms/order-growth.md": "4b03586ce9d75579f0a85be85445c1c4", + "algorithms/order-growth.md": "dd241870e1cfa0d43179a46213d5ed9c", "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "algorithms/sorting/selection-sort.md": "73415c44d6f4429f43c366078fd4bf98", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", @@ -246,7 +246,7 @@ "_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7", "_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd", "_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b", - "c17/strings.md": "c4da68e9280cda7bb5200382f83f6f6f", + "c17/strings.md": "cd4c15b6616613d2d2458aed3053306c", "c17/index.md": "78576ee41d0185df82c59999142f4edb", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", "c17/declarations.md": "65d2faaf8cc50878ad80126109e98b1f", @@ -437,17 +437,17 @@ "_journal/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b", "_journal/2024-05/2024-05-12.md": "ca9f3996272152ef89924bb328efd365", "git/remotes.md": "2208e34b3195b6f1ec041024a66fb38b", - "programming/pred-trans.md": "293806a24c2b9ef3fdb95ad74f9239b4", + "programming/pred-trans.md": "611dfb04df2126d35d67ca7ca1b39f52", "set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7", "_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5", "_journal/2024-05/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b", - "x86-64/registers.md": "be5e22ceb14084c34f446dd91702477b", + "x86-64/registers.md": "fb3cbacb2e0665c347ba0d4a9389fb69", "_journal/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908", "_journal/2024-05/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5", "_journal/2024-05-16.md": "580c7ec61ec56be92fa8d6affcf0a5f6", "_journal/2024-05/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908", "logic/pred-logic.md": "c23c3da8756ac0ef17b9710a67440d84", - "logic/prop-logic.md": "f7d3ae42989c1c226c40c8354a546264", + "logic/prop-logic.md": "ae3434527fbac9b01d536c955d4961ea", "_journal/2024-05-17.md": "fb880d68077b655ede36d994554f3aba", "_journal/2024-05/2024-05-16.md": "9fdfadc3f9ea6a4418fd0e7066d6b10c", "_journal/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c", @@ -467,7 +467,7 @@ "programming/λ-Calculus.md": "bf36bdaf85abffd171bb2087fb8228b2", "_journal/2024-05-23.md": "9d9106a68197adcee42cd19c69d2f840", "_journal/2024-05/2024-05-22.md": "3c29eec25f640183b0be365e7a023750", - "programming/lambda-calculus.md": "89f024561ea770552bc20056a45dbce6", + "programming/lambda-calculus.md": "1f14249f28c6acdeae7f55f701625a27", "_journal/2024-05-25.md": "04e8e1cf4bfdbfb286effed40b09c900", "_journal/2024-05/2024-05-24.md": "86132f18c7a27ebc7a3e4a07f4867858", "_journal/2024-05/2024-05-23.md": "d0c98b484b1def3a9fd7262dcf2050ad", @@ -483,7 +483,7 @@ "_journal/2024-05-29.md": "aee3f3766659789d7dfb63dd247844cc", "_journal/2024-05/2024-05-28.md": "28297d2a418f591ebc15c74fa459ddd9", "_journal/2024-05-30.md": "0467b8ded9cf1d9e3b419fa76f18f3c5", - "_journal/2024-05/2024-05-29.md": "ac77a3dfa0d0a538e7febd81886aba80", + "_journal/2024-05/2024-05-29.md": "e55105c3fd1bf99be8331b238e08d619", "_journal/2024-05-31.md": "93b6f1e2d4a03406d8e738091874fbe4", "_journal/2024-05/2024-05-30.md": "0b93c5b5e07130fac0e200754d68a450", "_journal/2024-06-01.md": "46c00cc59a2ae126ad54e9114ee97646", @@ -495,12 +495,25 @@ "programming/lean.md": "2815eac192c7e231937e2369817a6dc1", "logic/equality.md": "1867b676e0e7c9ec8f1addc40fefb966", "_journal/2024-06-04.md": "a7ca58741dbfdd7e351d835db3884c68", - "_journal/2024-06/2024-06-03.md": "3dbe96317f721515f3e6a20b82e3d537", + "_journal/2024-06/2024-06-03.md": "a7a2c3cfca8f932f0926701a2e2b0af9", "_journal/2024-06-05.md": "60f82c089f6911db8541a0bca7505ab4", "_journal/2024-06/2024-06-04.md": "52b28035b9c91c9b14cef1154c1a0fa1", "_journal/2024-06-06.md": "3f9109925dea304e7172df39922cc95a", "_journal/2024-06/2024-06-05.md": "b06a0fa567bd81e3b593f7e1838f9de1", - "set/relations.md": "411e81682aa5a731cd501031dc3ab59d" + "set/relations.md": "411e81682aa5a731cd501031dc3ab59d", + "_journal/2024-06-07.md": "795be41cc3c9c0f27361696d237604a2", + "_journal/2024-06/2024-06-06.md": "db3407dcc86fa759b061246ec9fbd381", + "_journal/2024-06-08.md": "b20d39dab30b4e12559a831ab8d2f9b8", + "_journal/2024-06/2024-06-07.md": "c6bfc4c1e5913d23ea7828a23340e7d3", + "lambda-calculus/alpha-conversion.md": "c0d40271a14b1f44b937de7791ca089b", + "lambda-calculus/index.md": "a03bdca6459a9094cabbb8992063ada6", + "x86-64/instructions/condition-codes.md": "56ad6eb395153609a1ec51835925e8c9", + "x86-64/instructions/logical.md": "818428b9ef84753920dc61e5c2de9199", + "x86-64/instructions/arithmetic.md": "271218d855e7291f119f96e91f582738", + "x86-64/instructions/access.md": "ab8605e11c0a3936735b18993e215513", + "x86-64/instructions/index.md": "72c19067e938ab39ea51d25d6ac2bad9", + "_journal/2024-06-09.md": "935b3ddf65c51e680ac5c000c7e380af", + "_journal/2024-06/2024-06-08.md": "9e1ebc8882a395b96ca765ad5c982d68" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-05/2024-05-29.md b/notes/_journal/2024-05/2024-05-29.md index df8a52b..94e153a 100644 --- a/notes/_journal/2024-05/2024-05-29.md +++ b/notes/_journal/2024-05/2024-05-29.md @@ -8,4 +8,4 @@ title: "2024-05-29" - [ ] Go (1 Life & Death Problem) - [ ] Korean (Read 1 Story) -* Flashcards on $\lambda$-calculus [[lambda-calculus#Substitution|substitution]]. Comparison to substitution as defined in Gries's equivalence-transformation system. \ No newline at end of file +* Flashcards on $\lambda$-calculus [[lambda-calculus/index#Substitution|substitution]]. Comparison to substitution as defined in Gries's equivalence-transformation system. \ No newline at end of file diff --git a/notes/_journal/2024-06-09.md b/notes/_journal/2024-06-09.md new file mode 100644 index 0000000..fb0856c --- /dev/null +++ b/notes/_journal/2024-06-09.md @@ -0,0 +1,11 @@ +--- +title: "2024-06-09" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Notes on [[registers|condition code registers]] and a [[condition-codes|few instruction classes]] that explicitly update them. \ No newline at end of file diff --git a/notes/_journal/2024-06/2024-06-03.md b/notes/_journal/2024-06/2024-06-03.md index 64dd7b4..7a84e24 100644 --- a/notes/_journal/2024-06/2024-06-03.md +++ b/notes/_journal/2024-06/2024-06-03.md @@ -8,4 +8,4 @@ title: "2024-06-03" - [ ] Sheet Music (10 min.) - [ ] Korean (Read 1 Story) -* Add notes on [[lambda-calculus#Syntactic Identity|syntactic identity]]. Relate this concept to Lean's syntactic equality. \ No newline at end of file +* Add notes on [[lambda-calculus/index#Syntactic Identity|syntactic identity]]. Relate this concept to Lean's syntactic equality. \ No newline at end of file diff --git a/notes/_journal/2024-06-06.md b/notes/_journal/2024-06/2024-06-06.md similarity index 57% rename from notes/_journal/2024-06-06.md rename to notes/_journal/2024-06/2024-06-06.md index ec90de7..2247ede 100644 --- a/notes/_journal/2024-06-06.md +++ b/notes/_journal/2024-06/2024-06-06.md @@ -8,4 +8,5 @@ title: "2024-06-06" - [ ] Sheet Music (10 min.) - [ ] Korean (Read 1 Story) -* Notes on [[relations#Overview|ordered pairs]]. \ No newline at end of file +* Notes on [[relations#Overview|ordered pairs]]. +* Notes on [[alpha-conversion|α-conversion]]. \ No newline at end of file diff --git a/notes/_journal/2024-06/2024-06-07.md b/notes/_journal/2024-06/2024-06-07.md new file mode 100644 index 0000000..8e45ad9 --- /dev/null +++ b/notes/_journal/2024-06/2024-06-07.md @@ -0,0 +1,9 @@ +--- +title: "2024-06-07" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) \ No newline at end of file diff --git a/notes/_journal/2024-06/2024-06-08.md b/notes/_journal/2024-06/2024-06-08.md new file mode 100644 index 0000000..c5c30a3 --- /dev/null +++ b/notes/_journal/2024-06/2024-06-08.md @@ -0,0 +1,13 @@ +--- +title: "2024-06-08" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Additional flashcards on [[alpha-conversion]]s. +* Watched [Learn RAG From Scratch](https://www.youtube.com/watch?v=sVcwVQRHIc8). +* Partially work through Ordered Pairs exercises in "Elements of Set Theory". \ No newline at end of file diff --git a/notes/algorithms/order-growth.md b/notes/algorithms/order-growth.md index 8297313..fae433e 100644 --- a/notes/algorithms/order-growth.md +++ b/notes/algorithms/order-growth.md @@ -214,7 +214,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition ( END%% -## $\Theta$-notation +## Θ-notation ![[theta-notation.png]] @@ -844,7 +844,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition ( END%% -## $\Omega$-notation +## Ω-notation ![[big-omega-notation.png]] @@ -1070,7 +1070,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition ( END%% -## $\omega$-notation +## ω-notation $\omega$-notation refers to a lower bound that is not asymptotically tight. It is defined as set $$\omega(g(n)) = \{ f(n) \mid \forall c > 0, \exists n_0 > 0, \forall n \geq n_0, 0 \leq cg(n) < f(n) \}$$ diff --git a/notes/c17/strings.md b/notes/c17/strings.md index b507c66..cbbf390 100644 --- a/notes/c17/strings.md +++ b/notes/c17/strings.md @@ -493,7 +493,7 @@ END%% %%ANKI Basic -Which format specifier were probably used to yield `printf` output `7af`? +Which format specifier was probably used to yield `printf` output `7af`? Back: `%x` Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). Tags: printf @@ -510,7 +510,7 @@ END%% %%ANKI Basic -Which format specifier were probably used to yield `printf` output `7AF`? +Which format specifier was probably used to yield `printf` output `7AF`? Back: `%X` Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). Tags: printf diff --git a/notes/lambda-calculus/alpha-conversion.md b/notes/lambda-calculus/alpha-conversion.md new file mode 100644 index 0000000..b20852b --- /dev/null +++ b/notes/lambda-calculus/alpha-conversion.md @@ -0,0 +1,318 @@ +--- +title: α-conversion +TARGET DECK: Obsidian::STEM +FILE TAGS: λ-calculus +tags: + - λ-calculus +--- + +## Overview + +Let $\lambda$-term $P$ contain an occurrence of $\lambda x. M$, and let $y \not\in FV(M)$. The act of replacing this occurrence of $\lambda x. M$ with $\lambda y. [y/x]M$ is called a **change of bound variable** or an $\alpha$-conversion in $P$. + +If $P$ can be changed to $\lambda$-term $Q$ by a finite series of changes of bound variables, we shall say **$P$ is congruent to $Q$**, or **$P$ $\alpha$-converts to $Q$**, or $P \equiv_\alpha Q$. + +%%ANKI +Basic +If $P \equiv Q$, does $P \equiv_\alpha Q$? +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $P \equiv_\alpha Q$, does $P \equiv Q$? +Back: Not necessarily. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +$\alpha$-conversion is most related to what kind of $\lambda$-term? +Back: Abstractions. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What property must $y$ satisfy for $\lambda x. M \equiv_\alpha \lambda y. M$? +Back: $y \not\in FV(M)$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What *kind* of conversion is a change of bound variable? +Back: An $\alpha$-conversion. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Given $\lambda$-terms $P$ and $Q$, what does it mean for $P$ to be congruent to $Q$? +Back: $P \equiv_\alpha Q$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Given $\lambda$-terms $P$ and $Q$, $P \equiv_\alpha Q$ if and only if what? +Back: $P$ can be changed to $Q$ with a finite number of changes of bound variables. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Is the following identity true? $$\lambda x y. x(xy) \equiv \lambda x. (\lambda y. x(xy))$$ +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Is the following identity true? $$\lambda x y. x(xy) \equiv_\alpha \lambda x. (\lambda y. x(xy))$$ +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Is the following identity true? $$\lambda x y. x(xy) \equiv \lambda u v. u(uv))$$ +Back: No. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Is the following identity true? $$\lambda x y. x(xy) \equiv_\alpha \lambda u v. u(uv))$$ +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Cloze +$\alpha$-conversion is known as a change of {bound variables}. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $P \equiv_\alpha Q$, what can be said about the free variables of $P$ and $Q$? +Back: $FV(P) = FV(Q)$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What does it mean for $\equiv_\alpha$ to be reflexive? +Back: $P \equiv_\alpha P$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What does it mean for $\equiv_\alpha$ to be symmetric? +Back: $P \equiv_\alpha Q \Rightarrow Q \equiv_\alpha P$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What does it mean for $\equiv_\alpha$ to be transitive? +Back: $P \equiv_\alpha Q \land Q \equiv_\alpha R \Rightarrow P \equiv_\alpha R$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What three properties make $\equiv_\alpha$ an equivalence relation? +Back: $\equiv_\alpha$ is reflexive, symmetric, and transitive. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +Let $x$, $y$, and $v$ be distinct variables. Then + +* $v \not\in FV(M) \Rightarrow [P/v][v/x]M \equiv_\alpha [P/x]M$ +* $v \not\in FV(M) \Rightarrow [x/v][v/x]M \equiv_\alpha M$ +* $y \not\in FV(P) \Rightarrow [P/x][Q/y]M \equiv_\alpha [([P/x]Q)/y][P/x]M$ + +%%ANKI +Basic +$[N/x]M$ corresponds to which equivalence-transformation inference rule? +Back: Substitution. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +$[P/v][v/x]M \equiv [P/x]M$ corresponds to which equivalence-transformation inference rule? +Back: Transitivity. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Rewrite $(E_u^x)_v^x$ using $\lambda$-calculus syntax. +Back: $[v/x][u/x]E$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Rewrite $[x/v][v/x]M$ using equivalence-transformation syntax. +Back: $(M^x_v)^v_x$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +$[P/v][v/x]M \equiv_\alpha [P/x]M$ is necessary for what condition? +Back: $v \not\in FV(M)$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What happens if the antecedent is false in $v \not\in FV(M) \Rightarrow [P/v][v/x]M \equiv_\alpha [P/x]M$? +Back: The LHS of the identity has more occurrences of $P$ than the right. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \in FV(M)$ and $x \not\in FV(M)$, does $[P/v][v/x]M \equiv_\alpha [P/x]M$? +Back: No. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \not\in FV(M)$ and $x \in FV(M)$, does $[P/v][v/x]M \equiv_\alpha [P/x]M$? +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \not\in FV(M)$, what simpler term is $[P/v][v/x]M$ congruent to? +Back: $[P/x]M$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \not\in FV(M)$ and $x \in FV(M)$, does $[x/v][v/x]M \equiv_\alpha M$? +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \not\in FV(M)$ and $x \in FV(M)$, does $[v/x][x/v]M \equiv_\alpha M$? +Back: No. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \in FV(M)$ and $x \not\in FV(M)$, does $[v/x][x/v]M \equiv_\alpha M$? +Back: Yes. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $v \in FV(M)$ and $x \not\in FV(M)$, does $[x/v][v/x]M \equiv_\alpha M$? +Back: No. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +If $y \not\in FV(P)$, "commuting" substitution in $[P/x][Q/y]M$ yields what congruent term? +Back: $[([P/x]Q)/y][P/x]M$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +$[P/x][Q/y]M \equiv_\alpha [([P/x]Q)/y][P/x]M$ is necessary for what condition? +Back: $y \not\in FV(P)$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +What happens if the antecedent is false in $y \not\in FV(P) \Rightarrow [P/x][Q/y]M \equiv_\alpha [([P/x]Q)/y][P/x]M$? +Back: $y$ is subbed in $M$ on the LHS but subbed in both $P$ and $M$ on the RHS. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Free occurrences of $x$ are substituted in which $\lambda$-terms of $[P/x][Q/y]M$? +Back: $Q$ and $M$. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Free occurrences of $y$ are substituted in which $\lambda$-terms of $[P/x][Q/y]M$? +Back: $M$ +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Free occurrences of $x$ are substituted in which $\lambda$-terms of $[([P/x]Q)/y][P/x]M$? +Back: $Q$ and $M$. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +%%ANKI +Basic +Free occurrences of $y$ are substituted in which $\lambda$-terms of $[([P/x]Q)/y][P/x]M$? +Back: $P$ and $M$. +Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). + +END%% + +## Bibliography + +* Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). \ No newline at end of file diff --git a/notes/programming/lambda-calculus.md b/notes/lambda-calculus/index.md similarity index 96% rename from notes/programming/lambda-calculus.md rename to notes/lambda-calculus/index.md index 31f8565..3d88d57 100644 --- a/notes/programming/lambda-calculus.md +++ b/notes/lambda-calculus/index.md @@ -251,7 +251,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -### Syntactic Identity +## Syntactic Identity **Syntactic identity** of terms is denoted by "$\equiv$". @@ -296,7 +296,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -### Length +## Length The length of a $\lambda$-term (denoted $lgh$) is equal to the number of atoms in the term: @@ -375,7 +375,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -### Occurrence +## Occurrence For $\lambda$-terms $P$ and $Q$, the relation **$P$ occurs in $Q$** is defined by induction on $Q$ as: @@ -494,7 +494,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -### Free and Bound Variables +## Free and Bound Variables An occurrence of a variable $x$ in a term $P$ is called @@ -655,7 +655,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -### Substitution +## Substitution For any $M$, $N$, and $x$, define $[N/x]M$ to be the result of substituting $N$ for every free occurrence of $x$ in $M$, and changing bound variables to avoid clashes. @@ -782,6 +782,7 @@ For all $\lambda$-terms $M$, $N$, and variables $x$: * $[x/x]M \equiv M$ * $x \not\in FV(M) \Rightarrow [N/x]M \equiv M$ * $x \in FV(M) \Rightarrow FV([N/x]M) = FV(N) \cup (FV(M) - \{x\})$ +* $lgh([y/x]M) = lgh(M)$ %%ANKI Basic @@ -823,38 +824,6 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi END%% -%%ANKI -Basic -$[N/x]M$ corresponds to which equivalence-transformation inference rule? -Back: Substitution. -Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). - -END%% - -%%ANKI -Basic -$[P/v][v/x]M \equiv [P/x]M$ corresponds to which equivalence-transformation inference rule? -Back: Transitivity. -Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). - -END%% - -%%ANKI -Basic -Rewrite $(E_u^x)_v^x$ using $\lambda$-calculus syntax. -Back: $[v/x][u/x]E$ -Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). - -END%% - -%%ANKI -Basic -Rewrite $[x/v][v/x]M$ using equivalence-transformation syntax. -Back: $(M^x_v)^v_x$ -Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). - -END%% - ## Bibliography * Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combinators, an Introduction,” n.d. [https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf](https://www.cin.ufpe.br/~djo/files/Lambda-Calculus%20and%20Combinators.pdf). \ No newline at end of file diff --git a/notes/logic/prop-logic.md b/notes/logic/prop-logic.md index 7d886cc..066febb 100644 --- a/notes/logic/prop-logic.md +++ b/notes/logic/prop-logic.md @@ -139,7 +139,7 @@ END%% %%ANKI Basic -How does "$P$ if $Q$" translate with $\Rightarrow$? +How do you write "$P$ if $Q$" in propositional logic? Back: $Q \Rightarrow P$ 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). @@ -147,7 +147,23 @@ END%% %%ANKI Basic -How does "$P$ only if $Q$" translate with $\Rightarrow$? +How do you write "$P$ if $Q$" using "necessary"? +Back: $P$ is necessary for $Q$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ if $Q$" using "sufficient"? +Back: $Q$ is sufficient for $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ only if $Q$" in propositional logic? Back: $P \Rightarrow Q$ 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). @@ -155,7 +171,23 @@ END%% %%ANKI Basic -How does "$P$ is necessary for $Q$" translate with $\Rightarrow$? +How do you write "$P$ only if $Q$" using "necessary"? +Back: $Q$ is necessary for $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ only if $Q$" using "sufficient"? +Back: $P$ is sufficient for $Q$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ is necessary for $Q$" in propositional logic? Back: $Q \Rightarrow P$ 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). @@ -163,7 +195,23 @@ END%% %%ANKI Basic -How does "$P$ is sufficient for $Q$" translate with $\Rightarrow$? +How do you write "$P$ is necessary for $Q$" using "if"? +Back: $P$ if $Q$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ is necessary for $Q$" using "only if"? +Back: $Q$ only if $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ is sufficient for $Q$" in propositional logic? Back: $P \Rightarrow Q$ 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). @@ -171,18 +219,50 @@ END%% %%ANKI Basic -Which of *if* or *only if* map to *necessary*? -Back: *if* +How do you write "$P$ is sufficient for $Q$" using "if"? +Back: $Q$ if $P$. 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). - + END%% %%ANKI Basic -Which of *if* or *only if* map to *sufficient*? -Back: *only if* +How do you write "$P$ is sufficient for $Q$" using "only if"? +Back: $P$ only if $Q$. 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). - + +END%% + +%%ANKI +Basic +How do you write "$P$ if $Q$" using "only if"? +Back: $Q$ only if $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ is sufficient for $Q$" using "necessary"? +Back: $Q$ is necessary for $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ only if $Q$" using "if"? +Back: $Q$ if $P$. +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). + +END%% + +%%ANKI +Basic +How do you write "$P$ is necessary for $Q$" using "sufficient"? +Back: $Q$ is sufficient for $P$. +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). + END%% %%ANKI diff --git a/notes/programming/pred-trans.md b/notes/programming/pred-trans.md index a6a21e1..f3dfee2 100644 --- a/notes/programming/pred-trans.md +++ b/notes/programming/pred-trans.md @@ -480,14 +480,6 @@ Reference: Gries, David. *The Science of Programming*. Texts and Monographs in END%% -%%ANKI -Basic -What constant operand evaluations determine the direction of implication in Distributivity of Disjunction? -Back: $F \Rightarrow T$ evaluates truthily but $T \Rightarrow F$ does not. -Reference: Gries, David. *The Science of Programming*. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981. - -END%% - %%ANKI Basic *Why* does Distributivity of Disjunction use an implication instead of equality? diff --git a/notes/x86-64/instructions.md b/notes/x86-64/instructions.md deleted file mode 100644 index d41dc5b..0000000 --- a/notes/x86-64/instructions.md +++ /dev/null @@ -1,1195 +0,0 @@ ---- -title: Instructions -TARGET DECK: Obsidian::STEM -FILE TAGS: x86-64 -tags: - - x86-64 ---- - -## Overview - -x86-64 instructions are designed so that commonly used instructions and those with fewer operands are encoded in a smaller number of bytes. Instructions range in length from 1 to 15 bytes. - -x86-64 assembly comes in two flavors: ATT and Intel. ATT is most common in Linux systems so I focus on that. The most important distinction between the two is operand ordering: Intel syntax lists multiple operands in reverse order compared to ATT. - -%%ANKI -Basic -x86-64 assembly comes in what two formats? -Back: ATT and Intel. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which x86-64 assembly format does Linux use? -Back: ATT. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which x86-64 assembly format does Microsoft use? -Back: Intel. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the "most confusing" difference between ATT and Intel assembly? -Back: Multiple operands in one are listed in reverse order relative to the other. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What term describes assembly lines with a leading `.`? -Back: Directives. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Assembly directives are important for what two programs? -Back: The assembler and the linker. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -## Instruction Classes - -There are three types of operands: - -* **Immediates**. These denote constant values. In ATT assembly, they are written with a `$` followed by an integer using standard C notation. -* **Registers**. These denote the contents of a register. -* **Memory**. These denote some memory location according to a computed address (i.e. the **effective address**). - -| Type | Form | Operand Value | Name | -| --------- | ----------------- | ---------------------------------- | ------------------- | -| Immediate | $\textdollar Imm$ | $Imm$ | Immediate | -| Register | $r_a$ | $R[r_a]$ | Register | -| Memory | $Imm$ | $M[Imm]$ | Absolute | -| Memory | $(r_a)$ | $M[R[r_a]]$ | Indirect | -| Memory | $Imm(r_b)$ | $M[Imm + R[r_b]]$ | Base + displacement | -| Memory | $(r_b, r_i)$ | $M[R[r_b] + R[r_i]]$ | Indexed | -| Memory | $Imm(r_b, r_i)$ | $M[Imm + R[r_b] + R[r_i]]$ | Indexed | -| Memory | $(,r_i,s)$ | $M[R[r_i] \cdot s]$ | Scaled indexed | -| Memory | $Imm(,r_i,s)$ | $M[Imm + R[r_i] \cdot s]$ | Scaled indexed | -| Memory | $(r_b,r_i,s)$ | $M[R[r_b] + R[r_i] \cdot s]$ | Scaled indexed | -| Memory | $Imm(r_b,r_i,s)$ | $M[Imm + R[r_b] + R[r_i] \cdot s]$ | Scaled indexed | - -%%ANKI -Basic -What are the types of source operands instructions can specify? -Back: Immediates, registers, and memory addresses. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What are the types of destination operands instructions can specify? -Back: Registers and memory addresses. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What does an immediate operand denote? -Back: A constant value. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -In ATT syntax, how is an immediate written? -Back: As a `$$` followed by an integer using standard C notation. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -In ATT syntax, how is a register written? -Back: As a `%` followed by the name of the register. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $\textdollar Imm$? -Back: $Imm$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $r_a$? -Back: $R[r_a]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $Imm$? -Back: $M[Imm]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $(r_a)$? -Back: $M[R[r_a]]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $Imm(r_b)$? -Back: $M[Imm + R[r_b]]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $(r_b, r_i)$? -Back: $M[R[r_b] + R[r_i]]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $Imm(r_b, r_i)$? -Back: $M[Imm + R[r_b] + R[r_i]]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $(,r_i,s)$? -Back: $M[R[r_i] \cdot s]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $Imm(,r_i,s)$? -Back: $M[Imm + R[r_i] \cdot s]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $(r_b,r_i,s)$? -Back: $M[R[r_b] + R[r_i] \cdot s]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the operand value of form $Imm(r_b,r_i,s)$? -Back: $M[Imm + R[r_b] + R[r_i] \cdot s]$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What distinguishes operand value $r_a$ from $(r_a)$? -Back: The former denotes the register value. The latter denotes the value in memory at the address stored in $r_a$. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What values can $s$ take on in operand form $Imm(r_b,r_i,s)$? -Back: $1$, $2$, $4$, or $8$. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What operand form is named "immediate"? -Back: $\textdollar Imm$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What operand form is named "register"? -Back: $r_a$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What operand form is named "absolute"? -Back: $Imm$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What operand form is named "indirect"? -Back: $(r_a)$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What operand form is named "base + displacement"? -Back: $Imm(r_b)$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the most general operand form named "indexed" (*not* "scaled indexed")? -Back: $Imm(r_b, r_i)$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the most general operand form named "scaled indexed" (*not* indexed)? -Back: $Imm(r_b, r_i, s)$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -### `MOV` - -The MOV instruction class has four primary variants: `movb`, `movw`, `movl`, and `movq`. There also exist zero extension and sign extension variations in the forms of MOVS and MOVZ. - -| Instruction | Operands | Effect | Description | -| ------------ | -------- | ---------------- | ------------------------------------ | -| `mov[bwlq]` | S, D | D <- S | Move byte/word/double word/quad word | -| `movabsq` | I, R | R <- I | Move quad word | -| `movzb[wlq]` | S, R | R <- ZE(S) | Move zero-extended byte | -| `movzw[lq]` | S, R | R <- ZE(S) | Move zero-extended word | -| `movsb[wlq]` | S, R | R <- SE(S) | Move sign-extended byte | -| `movsw[lq]` | S, R | R <- SE(S) | Move sign-extended word | -| `movslq` | S, R | R <- SE(S) | Move sign-extended double word | -| `cltq` | | %rax <- SE(%eax) | Sign-extend `%eax` to `%rax` | - -Notice there is no `movzlq` instruction. `movl` covers this functionality since, by convention, instructions moving double words into a 64-bit register automatically zeroes out the upper 32 bits. - -%%ANKI -Basic -What four variants does `MOV` instructions take on in x86-64? -Back: `movb`, `movw`, `movl`, `movq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many bytes does a `movb` instruction operate on? -Back: One. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many bytes does a `movw` instruction operate on? -Back: Two. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many bytes does a `movl` instruction operate on? -Back: Four. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many bytes does a `movq` instruction operate on? -Back: Eight. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What combination of source and destination types is prohibited in `MOV` instructions? -Back: A source and destination memory address. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after instruction `movl $0x4050,%eax`? -Back: Upper 32-bits is `0` and lower 32-bits is `0x4050`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after instruction `movq $0x4050,%rax`? -Back: The 64-bit value is `0x4050`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after instruction `movw $0x4050,%ax`? -Back: The upper 48 bits are unchanged and the lower 16 bits are `0x4050`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after instruction `movb $0x4050,%al`? -Back: The upper 56 bits are unchanged and the lower 8 bits are `0x50`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after instruction `movw $0x4050,%al`? -Back: N/A. Invalid operand for instruction. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What caveat is applied to the source operand of `movq`? -Back: Immediates are 32-bit two's-complement numbers sign extended to 64-bits. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What `mov` instruction is needed when working with 64-bit immediate sources? -Back: `movabsq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What purpose does `movabsq` solve that `movq` does not? -Back: `movabsq` can have an arbitrary 64-bit immediate source. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movb $-1, %al -``` -Back: `0x00112233445566FF` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movw $-1, %ax -``` -Back: `0x001122334455FFFF` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movl $-1, %eax -``` -Back: `0x00000000FFFFFFFF` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movq $-1, %rax -``` -Back: `0xFFFFFFFFFFFFFFFF` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the `MOVZ` instruction class? -Back: `MOV` instructions that zero extend the source to fit into the destination. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the `MOVS` instruction class? -Back: `MOV` instructions that sign extend the source to fit into the destination. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What does the `movzbw` instruction do? -Back: Moves a zero-extended byte to a word. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What does the `movslq` instruction do? -Back: Moves a sign-extended double word to a quad word. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What does the `movslb` instruction do? -Back: N/A. This instruction does not exist. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What combinatorial argument explains the number of `MOVS` instructions? -Back: There exists an instruction for each smaller declaration to larger declaration. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What `MOVZ` instruction is "missing"? -Back: `movzlq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Why does there not exist a `movzlq` instruction? -Back: Because `movl` already zeroes out the upper bits of a destination register. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movb $0xAA, %dl -movb %dl,%al -``` -Back: `0x00112233445566AA` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movb $0xAA, %dl -movsbq %dl,%rax -``` -Back: `0xFFFFFFFFFFFFFFAA` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the result of `%rax` after the following instructions? -```asm -movabsq $0x0011223344556677, %rax -movb $0xAA, %dl -movzbq %dl,%rax -``` -Back: `0x00000000000000AA` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -A {pointer} in C is a {memory address} in x86. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Dereferencing a pointer in C equates to what two operations in x86? -Back: Copying the pointer into a register and then using the register in a memory reference. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -### PUSH and POP - -| Instruction | Operands | Effect | Description | -| ----------- | -------- | ------------------------------------------- | -------------- | -| `pushq` | S | R[%rsp] <- R[%rsp] - 8
M[R[%rsp]] <- S | Push quad word | -| `popq` | D | D <- M[R[%rsp]]
R[%rsp] <- R[%rsp] + 8 | Pop quad word | - -In x86 processors, the stack grows downward, with the "top" of the stack corresponding to lower addresses. - -%%ANKI -Basic -In what direction do x86-64 stacks grow? -Back: Downward. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The x86-64 stack grows such that the top element has the {lowest} address of all stack elements. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What instruction is used to push elements onto the stack? -Back: `pushq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What instruction is used to pop elements off of the stack? -Back: `popq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is `pushq %rbp` equivalently written using a pair of instructions? -Back: -```asm -subq 8,%rsp -movq %rbp,(%rsp) -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is `popq %rax` equivalently written using a pair of instructions? -Back: -```asm -movq (%rsp),%rax -addq 8,%rsp -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -{1:`pushq`} is to {2:`subq`} as {2:`popq`} is to {1:`addq`}. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -If `%rsp` has value `0x108`, what value does it have after a `pushq` instruction? -Back: `0x100` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -If `%rsp` has value `0x108`, what value does it have after a `popq` instruction? -Back: `0x110` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which register contains a pointer to the top of the stack? -Back: `%rsp` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the `%rsp` register typically used for? -Back: The stack pointer. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -### Load Effective Address - -| Instruction | Operands | Effect | Description | -| ----------- | -------- | ------- | ---------------------- | -| `leaq` | S, D | D <- &S | Load effective address | - -`leaq` is a variant of MOV. The first operand appears to be a memory address, but instead of reading from the designated location, the instruction copies the effective address to the designated location (a register). - -%%ANKI -Basic -`leaq` is considered a variant of what other instruction class? -Back: `MOV` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Why is the `leaq` instruction named the way it is? -Back: It stands for **l**oad **e**ffective **a**ddress. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`leaq`} instruction is to x86-64 as the {`&`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which x86-64 instruction is used to generate pointers? -Back: `leaq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Why doesn't `leaq` have any other size variants? -Back: x96-64 addresses are always 64-bit. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Suppose `%rdx` contains $x$. Use `leaq` to set `%rax` to $5x + 7$. -Back: `leaq 7(%rdx, %rdx, 4), %rax` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Besides effective memory computations, how else is `leaq` used? -Back: For certain arithmetic operations. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Assume `%rdx` holds $q$. What is the value of `%rax` in the following? -```asm -leaq 9(%rdx),%rax -``` -Back: $9 + q$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Assume `%rbx` holds $p$ and `%rdx` holds $q$. What is the value of `%rax` in the following? -```asm -leaq (%rdx, %rbx),%rax -``` -Back: $q + q$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Assume `%rbx` holds $p$. What is the value of `%rax` in the following? -```asm -leaq 2(%rbx, %rbx, 7),%rax -``` -Back: $2 + 8p$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Assume `%rdx` holds $q$. What is the value of `%rax` in the following? -```asm -leaq 0xE(, %rdx, 3),%rax -``` -Back: $14 + 3q$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -### Unary Operations - -| Instruction | Operands | Effect | Description | -| ----------- | -------- | ---------- | ------------ | -| `inc[bwlq]` | D | D <- D + 1 | Increment | -| `dec[bwlq]` | D | D <- D - 1 | Decrement | -| `neg[bwlq]` | D | D <- -D | Negate | -| `not[bwlq]` | D | D <- ~D | Complement | - -%%ANKI -Basic -What four variants do `INC` instructions take on in x86-64? -Back: `incb`, `incw`, `incl`, `incq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D + 1$? -Back: `INC` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What source/destination types are permitted in unary instructions? -Back: Registers and memory addresses. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What do the instructions in the `INC` instruction class do? -Back: Increments the specified destination by $1$. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`INC`} instruction class is to x86-64 whereas the {`++`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -What do the instructions in the `DEC` instruction class do? -Back: Decrements the specified destination by $1$. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D - 1$? -Back: `DEC` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`DEC`} instruction class is to x86-64 whereas the {`--`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -What do the instructions in the `NEG` instruction class do? -Back: Negates the specified destination. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow -D$? -Back: `NEG` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`NEG`} instruction class is to x86-64 whereas the {`-`} *unary* operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -What do the instructions in the `NOT` instruction class do? -Back: Complements the specified destination. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow \textasciitilde D$? -Back: `NOT` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`NOT`} instruction class is to x86-64 whereas the {`~`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Cloze -{1:`NEG`} is to {2:negation} whereas {2:`NOT`} is to {1:complement}. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -### Binary Operations - -| Instruction | Operands | Effect | Description | -| ------------ | -------- | ----------- | -------------- | -| `add[bwlq]` | S, D | D <- D + S | Addition | -| `sub[bwlq]` | S, D | D <- D - S | Subtraction | -| `imul[bwlq]` | S, D | D <- D * S | Multiplication | -| `xor[bwlq]` | S, D | D <- D ^ S | Exclusive-or | -| `or[bwlq]` | S, D | D <- D \| S | Or | -| `and[bwlq]` | S, D | D <- D & S | And | - -%%ANKI -Basic -What four variants do `ADD` instructions take on in x86-64? -Back: `addb`, `addw`, `addl`, `addq` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What combination of source and destination types is prohibited in `ADD` instructions? -Back: A source and destination memory address. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D + S$? -Back: `ADD` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`ADD`} instruction class is to x86-64 as the {`+=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D - S$? -Back: `SUB` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which `SUB` instruction is equivalent to `decq %rcx`? -Back: -```asm -subq $1, %rcx -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How does Bryant et al. recommend reading `SUB` instructions? -Back: As subtracting the first operand *from* the second. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`SUB`} instruction class is to x86-64 as the {`-=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D * S$? -Back: `IMUL` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`IMUL`} instruction class is to x86-64 as the {`*=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D \;^\wedge\; S$? -Back: `XOR` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`XOR`} instruction class is to x86-64 as the {`^=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D \mid S$? -Back: `OR` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`OR`} instruction class is to x86-64 as the {`|=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -%%ANKI -Basic -Which instruction class corresponds to effect $D \leftarrow D \;\&\; S$? -Back: `AND` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -The {`AND`} instruction class is to x86-64 as the {`&=`} operator is to C. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: c17 - -END%% - -### Shift Operations - -| Instruction | Operands | Effect | Description | -| ----------- | -------- | ------------ | ---------------------- | -| `sal[bwlq]` | k, D | D <- D << k | Left shift | -| `shl[bwlq]` | k, D | D <- D << k | Left shift | -| `sar[bwlq]` | k, D | D <- D >> k | Arithmetic right shift | -| `shr[bwlq]` | k, D | D <- D >>> k | Logical right shift | - -%%ANKI -Basic -What do instructions in the `SAL` instruction class do? -Back: Performs a left shift. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What do instructions in the `SHL` instruction class do? -Back: Performs a left shift. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Which instruction classes are related to left shifts? -Back: `SAL` and `SHL`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - - -%%ANKI -Basic -Which instruction classes are related to right shifts? -Back: `SAR` and `SHR`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What do instructions in the `SAR` instruction class do? -Back: Performs an arithmetic right shift. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What do instructions in the `SHR` instruction class do? -Back: Performs a logical right shift. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What distinguishes the `SAR` and `SHR` instruction classes? -Back: The former is arithmetic whereas the latter is logical. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What distinguishes the `SAL` and `SHL` instruction classes? -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. - -END%% - -%%ANKI -Basic -Which register do shift operations refer to? -Back: `%cl` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many lower-order bits of `%cl` does e.g. `salb` look at? -Back: $3$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What can the source of a shift operation be? -Back: An immediate or the `%cl` register. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What can the destination of a shift operation be? -Back: A register or memory location. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many lower-order bits of `%cl` does e.g. `salw` look at? -Back: $4$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many lower-order bits of `%cl` does e.g. `sall` look at? -Back: $5$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many lower-order bits of `%cl` does e.g. `salq` look at? -Back: $6$ -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -## Bibliography - -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. diff --git a/notes/x86-64/instructions/access.md b/notes/x86-64/instructions/access.md new file mode 100644 index 0000000..82c4cc4 --- /dev/null +++ b/notes/x86-64/instructions/access.md @@ -0,0 +1,407 @@ +--- +title: Memory Access +TARGET DECK: Obsidian::STEM +FILE TAGS: x86-64 +tags: + - x86-64 +--- + +## MOV + +The MOV instruction class has four primary variants: `movb`, `movw`, `movl`, and `movq`. There also exist zero extension and sign extension variations in the forms of MOVS and MOVZ. + +| Instruction | Operands | Effect | Description | +| ------------ | -------- | ---------------- | ------------------------------------ | +| `mov[bwlq]` | S, D | D <- S | Move byte/word/double word/quad word | +| `movabsq` | I, R | R <- I | Move quad word | +| `movzb[wlq]` | S, R | R <- ZE(S) | Move zero-extended byte | +| `movzw[lq]` | S, R | R <- ZE(S) | Move zero-extended word | +| `movsb[wlq]` | S, R | R <- SE(S) | Move sign-extended byte | +| `movsw[lq]` | S, R | R <- SE(S) | Move sign-extended word | +| `movslq` | S, R | R <- SE(S) | Move sign-extended double word | +| `cltq` | | %rax <- SE(%eax) | Sign-extend `%eax` to `%rax` | + +Notice there is no `movzlq` instruction. `movl` covers this functionality since, by convention, instructions moving double words into a 64-bit register automatically zeroes out the upper 32 bits. + +%%ANKI +Basic +What four variants does `MOV` instructions take on in x86-64? +Back: `movb`, `movw`, `movl`, `movq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many bytes does a `movb` instruction operate on? +Back: One. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many bytes does a `movw` instruction operate on? +Back: Two. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many bytes does a `movl` instruction operate on? +Back: Four. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many bytes does a `movq` instruction operate on? +Back: Eight. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What combination of source and destination types is prohibited in `MOV` instructions? +Back: A source and destination memory address. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after instruction `movl $0x4050,%eax`? +Back: Upper 32-bits is `0` and lower 32-bits is `0x4050`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after instruction `movq $0x4050,%rax`? +Back: The 64-bit value is `0x4050`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after instruction `movw $0x4050,%ax`? +Back: The upper 48 bits are unchanged and the lower 16 bits are `0x4050`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after instruction `movb $0x4050,%al`? +Back: The upper 56 bits are unchanged and the lower 8 bits are `0x50`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after instruction `movw $0x4050,%al`? +Back: N/A. Invalid operand for instruction. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What caveat is applied to the source operand of `movq`? +Back: Immediates are 32-bit two's-complement numbers sign extended to 64-bits. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What `mov` instruction is needed when working with 64-bit immediate sources? +Back: `movabsq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What purpose does `movabsq` solve that `movq` does not? +Back: `movabsq` can have an arbitrary 64-bit immediate source. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movb $-1, %al +``` +Back: `0x00112233445566FF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movw $-1, %ax +``` +Back: `0x001122334455FFFF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movl $-1, %eax +``` +Back: `0x00000000FFFFFFFF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movq $-1, %rax +``` +Back: `0xFFFFFFFFFFFFFFFF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the `MOVZ` instruction class? +Back: `MOV` instructions that zero extend the source to fit into the destination. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the `MOVS` instruction class? +Back: `MOV` instructions that sign extend the source to fit into the destination. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What does the `movzbw` instruction do? +Back: Moves a zero-extended byte to a word. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What does the `movslq` instruction do? +Back: Moves a sign-extended double word to a quad word. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What does the `movslb` instruction do? +Back: N/A. This instruction does not exist. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What combinatorial argument explains the number of `MOVS` instructions? +Back: There exists an instruction for each smaller declaration to larger declaration. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What `MOVZ` instruction is "missing"? +Back: `movzlq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Why does there not exist a `movzlq` instruction? +Back: Because `movl` already zeroes out the upper bits of a destination register. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movb $0xAA, %dl +movb %dl,%al +``` +Back: `0x00112233445566AA` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movb $0xAA, %dl +movsbq %dl,%rax +``` +Back: `0xFFFFFFFFFFFFFFAA` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the result of `%rax` after the following instructions? +```asm +movabsq $0x0011223344556677, %rax +movb $0xAA, %dl +movzbq %dl,%rax +``` +Back: `0x00000000000000AA` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +A {pointer} in C is a {memory address} in x86. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Dereferencing a pointer in C equates to what two operations in x86? +Back: Copying the pointer into a register and then using the register in a memory reference. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +## PUSH and POP + +| Instruction | Operands | Effect | Description | +| ----------- | -------- | ------------------------------------------- | -------------- | +| `pushq` | S | R[%rsp] <- R[%rsp] - 8
M[R[%rsp]] <- S | Push quad word | +| `popq` | D | D <- M[R[%rsp]]
R[%rsp] <- R[%rsp] + 8 | Pop quad word | + +In x86 processors, the stack grows downward, with the "top" of the stack corresponding to lower addresses. + +%%ANKI +Basic +In what direction do x86-64 stacks grow? +Back: Downward. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The x86-64 stack grows such that the top element has the {lowest} address of all stack elements. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What instruction is used to push elements onto the stack? +Back: `pushq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What instruction is used to pop elements off of the stack? +Back: `popq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is `pushq %rbp` equivalently written using a pair of instructions? +Back: +```asm +subq 8,%rsp +movq %rbp,(%rsp) +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is `popq %rax` equivalently written using a pair of instructions? +Back: +```asm +movq (%rsp),%rax +addq 8,%rsp +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +{1:`pushq`} is to {2:`subq`} as {2:`popq`} is to {1:`addq`}. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +If `%rsp` has value `0x108`, what value does it have after a `pushq` instruction? +Back: `0x100` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +If `%rsp` has value `0x108`, what value does it have after a `popq` instruction? +Back: `0x110` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which register contains a pointer to the top of the stack? +Back: `%rsp` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the `%rsp` register typically used for? +Back: The stack pointer. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% \ No newline at end of file diff --git a/notes/x86-64/instructions/arithmetic.md b/notes/x86-64/instructions/arithmetic.md new file mode 100644 index 0000000..c745f65 --- /dev/null +++ b/notes/x86-64/instructions/arithmetic.md @@ -0,0 +1,413 @@ +--- +title: Arithmetic Operations +TARGET DECK: Obsidian::STEM +FILE TAGS: x86-64 +tags: + - x86-64 +--- + +### Load Effective Address + +| Instruction | Operands | Effect | Description | +| ----------- | -------- | ------- | ---------------------- | +| `leaq` | S, D | D <- &S | Load effective address | + +`leaq` is a variant of MOV. The first operand appears to be a memory address, but instead of reading from the designated location, the instruction copies the effective address to the designated location (a register). + +%%ANKI +Basic +`leaq` is considered a variant of what other instruction class? +Back: `MOV` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Why is the `leaq` instruction named the way it is? +Back: It stands for **l**oad **e**ffective **a**ddress. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`leaq`} instruction is to x86-64 as the {`&`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Which x86-64 instruction is used to generate pointers? +Back: `leaq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Why doesn't `leaq` have any other size variants? +Back: x96-64 addresses are always 64-bit. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Suppose `%rdx` contains $x$. Use `leaq` to set `%rax` to $5x + 7$. +Back: `leaq 7(%rdx, %rdx, 4), %rax` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Besides effective memory computations, how else is `leaq` used? +Back: For certain arithmetic operations. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Assume `%rdx` holds $q$. What is the value of `%rax` in the following? +```asm +leaq 9(%rdx),%rax +``` +Back: $9 + q$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Assume `%rbx` holds $p$ and `%rdx` holds $q$. What is the value of `%rax` in the following? +```asm +leaq (%rdx, %rbx),%rax +``` +Back: $q + q$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Assume `%rbx` holds $p$. What is the value of `%rax` in the following? +```asm +leaq 2(%rbx, %rbx, 7),%rax +``` +Back: $2 + 8p$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Assume `%rdx` holds $q$. What is the value of `%rax` in the following? +```asm +leaq 0xE(, %rdx, 3),%rax +``` +Back: $14 + 3q$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +### Unary Operations + +| Instruction | Operands | Effect | Description | +| ----------- | -------- | ---------- | ----------- | +| `inc[bwlq]` | D | D <- D + 1 | Increment | +| `dec[bwlq]` | D | D <- D - 1 | Decrement | + +%%ANKI +Basic +What four variants do `INC` instructions take on in x86-64? +Back: `incb`, `incw`, `incl`, `incq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D + 1$? +Back: `INC` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What source/destination types are permitted in unary instructions? +Back: Registers and memory addresses. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What do the instructions in the `INC` instruction class do? +Back: Increments the specified destination by $1$. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`INC`} instruction class is to x86-64 whereas the {`++`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +What do the instructions in the `DEC` instruction class do? +Back: Decrements the specified destination by $1$. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D - 1$? +Back: `DEC` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`DEC`} instruction class is to x86-64 whereas the {`--`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + + + +### Binary Operations + +| Instruction | Operands | Effect | Description | +| ------------ | -------- | ----------- | -------------- | +| `add[bwlq]` | S, D | D <- D + S | Addition | +| `sub[bwlq]` | S, D | D <- D - S | Subtraction | +| `imul[bwlq]` | S, D | D <- D * S | Multiplication | + +%%ANKI +Basic +What four variants do `ADD` instructions take on in x86-64? +Back: `addb`, `addw`, `addl`, `addq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What combination of source and destination types is prohibited in `ADD` instructions? +Back: A source and destination memory address. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D + S$? +Back: `ADD` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`ADD`} instruction class is to x86-64 as the {`+=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D - S$? +Back: `SUB` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which `SUB` instruction is equivalent to `decq %rcx`? +Back: +```asm +subq $1, %rcx +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How does Bryant et al. recommend reading `SUB` instructions? +Back: As subtracting the first operand *from* the second. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`SUB`} instruction class is to x86-64 as the {`-=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D * S$? +Back: `IMUL` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`IMUL`} instruction class is to x86-64 as the {`*=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +### Shift Operations + +| Instruction | Operands | Effect | Description | +| ----------- | -------- | ------------ | ---------------------- | +| `sal[bwlq]` | k, D | D <- D << k | Left shift | +| `shl[bwlq]` | k, D | D <- D << k | Left shift | +| `sar[bwlq]` | k, D | D <- D >> k | Arithmetic right shift | +| `shr[bwlq]` | k, D | D <- D >>> k | Logical right shift | + +%%ANKI +Basic +What do instructions in the `SAL` instruction class do? +Back: Performs a left shift. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What do instructions in the `SHL` instruction class do? +Back: Performs a left shift. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction classes are related to left shifts? +Back: `SAL` and `SHL`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + + +%%ANKI +Basic +Which instruction classes are related to right shifts? +Back: `SAR` and `SHR`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What do instructions in the `SAR` instruction class do? +Back: Performs an arithmetic right shift. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What do instructions in the `SHR` instruction class do? +Back: Performs a logical right shift. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What distinguishes the `SAR` and `SHR` instruction classes? +Back: The former is arithmetic whereas the latter is logical. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What distinguishes the `SAL` and `SHL` instruction classes? +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. + +END%% + +%%ANKI +Basic +Which register do shift operations refer to? +Back: `%cl` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many lower-order bits of `%cl` does e.g. `salb` look at? +Back: $3$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What can the source of a shift operation be? +Back: An immediate or the `%cl` register. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What can the destination of a shift operation be? +Back: A register or memory location. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many lower-order bits of `%cl` does e.g. `salw` look at? +Back: $4$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many lower-order bits of `%cl` does e.g. `sall` look at? +Back: $5$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many lower-order bits of `%cl` does e.g. `salq` look at? +Back: $6$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Bibliography + +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file diff --git a/notes/x86-64/instructions/condition-codes.md b/notes/x86-64/instructions/condition-codes.md new file mode 100644 index 0000000..34357b0 --- /dev/null +++ b/notes/x86-64/instructions/condition-codes.md @@ -0,0 +1,97 @@ +--- +title: Condition Code Operations +TARGET DECK: Obsidian::STEM +FILE TAGS: x86-64 +tags: + - x86-64 +--- + +## Overview + +| Instruction | Operands | Based On | Description | +| ------------ | ---------- | --------------------- | ----------- | +| `cmp[bwlq]` | $S_1, S_2$ | $S_2 - S_1$ | Compare | +| `test[bwlq]` | $S_1, S_2$ | $S_1 \mathop{\&} S_2$ | Test | + +%%ANKI +Basic +What four variants do `CMP` instructions take on in x86-64? +Back: `cmpb`, `cmpw`, `cmpl`, `cmpq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What instruction class is `CMP` "based" on? +Back: `SUB` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What registers does `CMP` affect? +Back: The condition code registers. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What distinguishes `CMP` from `SUB`? +Back: `CMP` does not update any destinations. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How does Bryant et al. recommend reading `CMP` instructions? +Back: As subtracting the first operand *from* the second. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What instruction class is `TEST` "based" on? +Back: `AND` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What distinguishes `TEST` from `AND`? +Back: `TEST` does not update any destinations. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What four variants do `TEST` instructions take on in x86-64? +Back: `testb`, `testw`, `testl`, `testq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +{1:`CMP`} is to {2:`SUB`} as {2:`TEST`} is to {1:`AND`}. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What registers does `TEST` affect? +Back: The condition code registers. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Bibliography + +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. diff --git a/notes/x86-64/instructions/index.md b/notes/x86-64/instructions/index.md new file mode 100644 index 0000000..1e0cad3 --- /dev/null +++ b/notes/x86-64/instructions/index.md @@ -0,0 +1,287 @@ +--- +title: Instructions +TARGET DECK: Obsidian::STEM +FILE TAGS: x86-64 +tags: + - x86-64 +--- + +## Overview + +x86-64 instructions are designed so that commonly used instructions and those with fewer operands are encoded in a smaller number of bytes. Instructions range in length from 1 to 15 bytes. + +x86-64 assembly comes in two flavors: ATT and Intel. ATT is most common in Linux systems so I focus on that. The most important distinction between the two is operand ordering: Intel syntax lists multiple operands in reverse order compared to ATT. + +%%ANKI +Basic +x86-64 assembly comes in what two formats? +Back: ATT and Intel. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which x86-64 assembly format does Linux use? +Back: ATT. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which x86-64 assembly format does Microsoft use? +Back: Intel. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the "most confusing" difference between ATT and Intel assembly? +Back: Multiple operands in one are listed in reverse order relative to the other. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What term describes assembly lines with a leading `.`? +Back: Directives. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Assembly directives are important for what two programs? +Back: The assembler and the linker. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Instruction Classes + +There are three types of operands: + +* **Immediates**. These denote constant values. In ATT assembly, they are written with a `$` followed by an integer using standard C notation. +* **Registers**. These denote the contents of a register. +* **Memory**. These denote some memory location according to a computed address (i.e. the **effective address**). + +| Type | Form | Operand Value | Name | +| --------- | ----------------- | ---------------------------------- | ------------------- | +| Immediate | $\textdollar Imm$ | $Imm$ | Immediate | +| Register | $r_a$ | $R[r_a]$ | Register | +| Memory | $Imm$ | $M[Imm]$ | Absolute | +| Memory | $(r_a)$ | $M[R[r_a]]$ | Indirect | +| Memory | $Imm(r_b)$ | $M[Imm + R[r_b]]$ | Base + displacement | +| Memory | $(r_b, r_i)$ | $M[R[r_b] + R[r_i]]$ | Indexed | +| Memory | $Imm(r_b, r_i)$ | $M[Imm + R[r_b] + R[r_i]]$ | Indexed | +| Memory | $(,r_i,s)$ | $M[R[r_i] \cdot s]$ | Scaled indexed | +| Memory | $Imm(,r_i,s)$ | $M[Imm + R[r_i] \cdot s]$ | Scaled indexed | +| Memory | $(r_b,r_i,s)$ | $M[R[r_b] + R[r_i] \cdot s]$ | Scaled indexed | +| Memory | $Imm(r_b,r_i,s)$ | $M[Imm + R[r_b] + R[r_i] \cdot s]$ | Scaled indexed | + +%%ANKI +Basic +What are the types of source operands instructions can specify? +Back: Immediates, registers, and memory addresses. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What are the types of destination operands instructions can specify? +Back: Registers and memory addresses. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What does an immediate operand denote? +Back: A constant value. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +In ATT syntax, how is an immediate written? +Back: As a `$$` followed by an integer using standard C notation. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +In ATT syntax, how is a register written? +Back: As a `%` followed by the name of the register. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $\textdollar Imm$? +Back: $Imm$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $r_a$? +Back: $R[r_a]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $Imm$? +Back: $M[Imm]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $(r_a)$? +Back: $M[R[r_a]]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $Imm(r_b)$? +Back: $M[Imm + R[r_b]]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $(r_b, r_i)$? +Back: $M[R[r_b] + R[r_i]]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $Imm(r_b, r_i)$? +Back: $M[Imm + R[r_b] + R[r_i]]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $(,r_i,s)$? +Back: $M[R[r_i] \cdot s]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $Imm(,r_i,s)$? +Back: $M[Imm + R[r_i] \cdot s]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $(r_b,r_i,s)$? +Back: $M[R[r_b] + R[r_i] \cdot s]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the operand value of form $Imm(r_b,r_i,s)$? +Back: $M[Imm + R[r_b] + R[r_i] \cdot s]$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What distinguishes operand value $r_a$ from $(r_a)$? +Back: The former denotes the register value. The latter denotes the value in memory at the address stored in $r_a$. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What values can $s$ take on in operand form $Imm(r_b,r_i,s)$? +Back: $1$, $2$, $4$, or $8$. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What operand form is named "immediate"? +Back: $\textdollar Imm$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What operand form is named "register"? +Back: $r_a$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What operand form is named "absolute"? +Back: $Imm$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What operand form is named "indirect"? +Back: $(r_a)$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What operand form is named "base + displacement"? +Back: $Imm(r_b)$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the most general operand form named "indexed" (*not* "scaled indexed")? +Back: $Imm(r_b, r_i)$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the most general operand form named "scaled indexed" (*not* indexed)? +Back: $Imm(r_b, r_i, s)$ +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Bibliography + +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file diff --git a/notes/x86-64/instructions/logical.md b/notes/x86-64/instructions/logical.md new file mode 100644 index 0000000..85187cb --- /dev/null +++ b/notes/x86-64/instructions/logical.md @@ -0,0 +1,129 @@ +--- +title: " Logical Operations" +TARGET DECK: Obsidian::STEM +FILE TAGS: x86-64 +tags: + - x86-64 +--- + +### Unary Operations + +| Instruction | Operands | Effect | Description | +| ----------- | -------- | ---------- | ----------- | +| `neg[bwlq]` | D | D <- -D | Negate | +| `not[bwlq]` | D | D <- ~D | Complement | + +%%ANKI +Basic +What do the instructions in the `NEG` instruction class do? +Back: Negates the specified destination. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow -D$? +Back: `NEG` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`NEG`} instruction class is to x86-64 whereas the {`-`} *unary* operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +What do the instructions in the `NOT` instruction class do? +Back: Complements the specified destination. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow \textasciitilde D$? +Back: `NOT` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`NOT`} instruction class is to x86-64 whereas the {`~`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Cloze +{1:`NEG`} is to {2:negation} whereas {2:`NOT`} is to {1:complement}. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Binary Operations + +| Instruction | Operands | Effect | Description | +| ------------ | -------- | ----------- | -------------- | +| `xor[bwlq]` | S, D | D <- D ^ S | Exclusive-or | +| `or[bwlq]` | S, D | D <- D \| S | Or | +| `and[bwlq]` | S, D | D <- D & S | And | + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D \;^\wedge\; S$? +Back: `XOR` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`XOR`} instruction class is to x86-64 as the {`^=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D \mid S$? +Back: `OR` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`OR`} instruction class is to x86-64 as the {`|=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Which instruction class corresponds to effect $D \leftarrow D \;\&\; S$? +Back: `AND` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +The {`AND`} instruction class is to x86-64 as the {`&=`} operator is to C. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +## Bibliography + +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file diff --git a/notes/x86-64/registers.md b/notes/x86-64/registers.md index aac4f6d..e3e56ed 100644 --- a/notes/x86-64/registers.md +++ b/notes/x86-64/registers.md @@ -83,6 +83,186 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +The CPU also maintains a set of single-bit **condition code** registers describing attributes of the most recent arithmetic or logical operation. + +Code | Name | Description +-----| ------------- | ----------- +`CF` | Carry flag | The most recent operation generated a carry out of the most significant bit. +`ZF` | Zero flag | The most recent operation yielded zero. +`SF` | Sign flag | The most recent operation yielded a negative value. +`OF` | Overflow flag | The most recent operation caused a two's-complement overflow. + +%%ANKI +Basic +Condition code registers describe attributes of what kind of operations? +Back: Arithmetic and logical. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +{Condition code} registers describe attributes of the most recent arithmetic/logical operation. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How large is a condition code register? +Back: A single bit. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +`CF` and `SF` are examples of what? +Back: Condition codes. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Condition code `CF` is an acronym for what? +Back: **C**arry **f**lag. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Condition code `ZF` is an acronym for what? +Back: **Z**ero **f**lag. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +When is the `ZF` condition code set? +Back: When the most recent operation yielded a zero. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Condition code `SF` is an acronym for what? +Back: **S**ign **f**lag. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +When is the `SF` condition code set? +Back: When the most recent operation yielded a negative value. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Condition code `OF` is an acronym for what? +Back: **O**verflow **f**lag. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which condition code is checked for unsigned overflow? +Back: `CF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +When is the `CF` condition code set? +Back: When the most recent operation generated a carry out of the most significant bit. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which condition code is checked for two's-complement positive overflow? +Back: `OF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +When is the `OF` condition code set? +Back: When the most recent operation caused a two's-complement overflow. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which condition code is checked for two's-complement negative overflow? +Back: `OF` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Evaluate `int t = a + b` for `int` `a` and `b`. When is `CF` set? +Back: When `(unsigned) t < (unsigned) a`. +Tags: c17 +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Evaluate `int t = a + b` for `int` `a` and `b`. When is `ZF` set? +Back: When `t == 0`. +Tags: c17 +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Evaluate `int t = a + b` for `int` `a` and `b`. When is `SF` set? +Back: When `t < 0`. +Tags: c17 +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Evaluate `int t = a + b` for `int` `a` and `b`. When is `OF` set? +Back: When `(t <= 0 && a > 0 && b > 0) || (t >= 0 && a < 0 && b < 0)`. +Tags: c17 +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Which "arithmetic" instruction does not alter condition codes? +Back: `leaq` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +*Why* doesn't `leaq` alter condition codes? +Back: It is intended for address computation. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + ## Bibliography -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.