Condition code registers.

c-declarations
Joshua Potter 2024-06-09 07:58:36 -06:00
parent cfa95d2390
commit 044b58e0c6
20 changed files with 1992 additions and 1268 deletions

View File

@ -178,7 +178,7 @@
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2", "algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
"algorithms/loop-invariant.md": "3b390e720f3b2a98e611b49a0bb1f5a9", "algorithms/loop-invariant.md": "3b390e720f3b2a98e611b49a0bb1f5a9",
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65", "algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
"algorithms/order-growth.md": "4b03586ce9d75579f0a85be85445c1c4", "algorithms/order-growth.md": "dd241870e1cfa0d43179a46213d5ed9c",
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
"algorithms/sorting/selection-sort.md": "73415c44d6f4429f43c366078fd4bf98", "algorithms/sorting/selection-sort.md": "73415c44d6f4429f43c366078fd4bf98",
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
@ -246,7 +246,7 @@
"_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7", "_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7",
"_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd", "_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd",
"_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b", "_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b",
"c17/strings.md": "c4da68e9280cda7bb5200382f83f6f6f", "c17/strings.md": "cd4c15b6616613d2d2458aed3053306c",
"c17/index.md": "78576ee41d0185df82c59999142f4edb", "c17/index.md": "78576ee41d0185df82c59999142f4edb",
"c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500",
"c17/declarations.md": "65d2faaf8cc50878ad80126109e98b1f", "c17/declarations.md": "65d2faaf8cc50878ad80126109e98b1f",
@ -437,17 +437,17 @@
"_journal/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b", "_journal/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b",
"_journal/2024-05/2024-05-12.md": "ca9f3996272152ef89924bb328efd365", "_journal/2024-05/2024-05-12.md": "ca9f3996272152ef89924bb328efd365",
"git/remotes.md": "2208e34b3195b6f1ec041024a66fb38b", "git/remotes.md": "2208e34b3195b6f1ec041024a66fb38b",
"programming/pred-trans.md": "293806a24c2b9ef3fdb95ad74f9239b4", "programming/pred-trans.md": "611dfb04df2126d35d67ca7ca1b39f52",
"set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7", "set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7",
"_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5", "_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
"_journal/2024-05/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b", "_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-15.md": "4e6a7e6df32e93f0d8a56bc76613d908",
"_journal/2024-05/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5", "_journal/2024-05/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
"_journal/2024-05-16.md": "580c7ec61ec56be92fa8d6affcf0a5f6", "_journal/2024-05-16.md": "580c7ec61ec56be92fa8d6affcf0a5f6",
"_journal/2024-05/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908", "_journal/2024-05/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908",
"logic/pred-logic.md": "c23c3da8756ac0ef17b9710a67440d84", "logic/pred-logic.md": "c23c3da8756ac0ef17b9710a67440d84",
"logic/prop-logic.md": "f7d3ae42989c1c226c40c8354a546264", "logic/prop-logic.md": "ae3434527fbac9b01d536c955d4961ea",
"_journal/2024-05-17.md": "fb880d68077b655ede36d994554f3aba", "_journal/2024-05-17.md": "fb880d68077b655ede36d994554f3aba",
"_journal/2024-05/2024-05-16.md": "9fdfadc3f9ea6a4418fd0e7066d6b10c", "_journal/2024-05/2024-05-16.md": "9fdfadc3f9ea6a4418fd0e7066d6b10c",
"_journal/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c", "_journal/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c",
@ -467,7 +467,7 @@
"programming/λ-Calculus.md": "bf36bdaf85abffd171bb2087fb8228b2", "programming/λ-Calculus.md": "bf36bdaf85abffd171bb2087fb8228b2",
"_journal/2024-05-23.md": "9d9106a68197adcee42cd19c69d2f840", "_journal/2024-05-23.md": "9d9106a68197adcee42cd19c69d2f840",
"_journal/2024-05/2024-05-22.md": "3c29eec25f640183b0be365e7a023750", "_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-25.md": "04e8e1cf4bfdbfb286effed40b09c900",
"_journal/2024-05/2024-05-24.md": "86132f18c7a27ebc7a3e4a07f4867858", "_journal/2024-05/2024-05-24.md": "86132f18c7a27ebc7a3e4a07f4867858",
"_journal/2024-05/2024-05-23.md": "d0c98b484b1def3a9fd7262dcf2050ad", "_journal/2024-05/2024-05-23.md": "d0c98b484b1def3a9fd7262dcf2050ad",
@ -483,7 +483,7 @@
"_journal/2024-05-29.md": "aee3f3766659789d7dfb63dd247844cc", "_journal/2024-05-29.md": "aee3f3766659789d7dfb63dd247844cc",
"_journal/2024-05/2024-05-28.md": "28297d2a418f591ebc15c74fa459ddd9", "_journal/2024-05/2024-05-28.md": "28297d2a418f591ebc15c74fa459ddd9",
"_journal/2024-05-30.md": "0467b8ded9cf1d9e3b419fa76f18f3c5", "_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-31.md": "93b6f1e2d4a03406d8e738091874fbe4",
"_journal/2024-05/2024-05-30.md": "0b93c5b5e07130fac0e200754d68a450", "_journal/2024-05/2024-05-30.md": "0b93c5b5e07130fac0e200754d68a450",
"_journal/2024-06-01.md": "46c00cc59a2ae126ad54e9114ee97646", "_journal/2024-06-01.md": "46c00cc59a2ae126ad54e9114ee97646",
@ -495,12 +495,25 @@
"programming/lean.md": "2815eac192c7e231937e2369817a6dc1", "programming/lean.md": "2815eac192c7e231937e2369817a6dc1",
"logic/equality.md": "1867b676e0e7c9ec8f1addc40fefb966", "logic/equality.md": "1867b676e0e7c9ec8f1addc40fefb966",
"_journal/2024-06-04.md": "a7ca58741dbfdd7e351d835db3884c68", "_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-05.md": "60f82c089f6911db8541a0bca7505ab4",
"_journal/2024-06/2024-06-04.md": "52b28035b9c91c9b14cef1154c1a0fa1", "_journal/2024-06/2024-06-04.md": "52b28035b9c91c9b14cef1154c1a0fa1",
"_journal/2024-06-06.md": "3f9109925dea304e7172df39922cc95a", "_journal/2024-06-06.md": "3f9109925dea304e7172df39922cc95a",
"_journal/2024-06/2024-06-05.md": "b06a0fa567bd81e3b593f7e1838f9de1", "_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": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -8,4 +8,4 @@ title: "2024-05-29"
- [ ] Go (1 Life & Death Problem) - [ ] Go (1 Life & Death Problem)
- [ ] Korean (Read 1 Story) - [ ] Korean (Read 1 Story)
* Flashcards on $\lambda$-calculus [[lambda-calculus#Substitution|substitution]]. Comparison to substitution as defined in Gries's equivalence-transformation system. * Flashcards on $\lambda$-calculus [[lambda-calculus/index#Substitution|substitution]]. Comparison to substitution as defined in Gries's equivalence-transformation system.

View File

@ -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.

View File

@ -8,4 +8,4 @@ title: "2024-06-03"
- [ ] Sheet Music (10 min.) - [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story) - [ ] Korean (Read 1 Story)
* Add notes on [[lambda-calculus#Syntactic Identity|syntactic identity]]. Relate this concept to Lean's syntactic equality. * Add notes on [[lambda-calculus/index#Syntactic Identity|syntactic identity]]. Relate this concept to Lean's syntactic equality.

View File

@ -9,3 +9,4 @@ title: "2024-06-06"
- [ ] Korean (Read 1 Story) - [ ] Korean (Read 1 Story)
* Notes on [[relations#Overview|ordered pairs]]. * Notes on [[relations#Overview|ordered pairs]].
* Notes on [[alpha-conversion|α-conversion]].

View File

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

View File

@ -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".

View File

@ -214,7 +214,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (
<!--ID: 1709519002319--> <!--ID: 1709519002319-->
END%% END%%
## $\Theta$-notation ## Θ-notation
![[theta-notation.png]] ![[theta-notation.png]]
@ -844,7 +844,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (
<!--ID: 1709752223449--> <!--ID: 1709752223449-->
END%% END%%
## $\Omega$-notation ## Ω-notation
![[big-omega-notation.png]] ![[big-omega-notation.png]]
@ -1070,7 +1070,7 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (
<!--ID: 1709752223522--> <!--ID: 1709752223522-->
END%% 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) \}$$ $\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) \}$$

View File

@ -493,7 +493,7 @@ END%%
%%ANKI %%ANKI
Basic 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` 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). 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 Tags: printf
@ -510,7 +510,7 @@ END%%
%%ANKI %%ANKI
Basic 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` 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). 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 Tags: printf

View File

@ -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).
<!--ID: 1717687744134-->
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).
<!--ID: 1717687744141-->
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).
<!--ID: 1717687744144-->
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).
<!--ID: 1717687744147-->
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).
<!--ID: 1717687744150-->
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).
<!--ID: 1717687744154-->
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).
<!--ID: 1717687744157-->
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).
<!--ID: 1717687744162-->
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).
<!--ID: 1717687744166-->
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).
<!--ID: 1717687744169-->
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).
<!--ID: 1717687744173-->
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).
<!--ID: 1717687744176-->
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).
<!--ID: 1717848027572-->
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).
<!--ID: 1717848027575-->
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).
<!--ID: 1717848027579-->
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).
<!--ID: 1717848027582-->
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).
<!--ID: 1717848027586-->
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).
<!--ID: 1717449830572-->
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).
<!--ID: 1717449830601-->
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).
<!--ID: 1717449830608-->
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).
<!--ID: 1717449830614-->
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).
<!--ID: 1717855810777-->
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).
<!--ID: 1717855810781-->
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).
<!--ID: 1717850495760-->
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).
<!--ID: 1717850495763-->
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).
<!--ID: 1717850495766-->
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).
<!--ID: 1717850495775-->
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).
<!--ID: 1717850495778-->
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).
<!--ID: 1717850495782-->
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).
<!--ID: 1717850495785-->
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).
<!--ID: 1717853380814-->
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).
<!--ID: 1717855810784-->
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).
<!--ID: 1717855810787-->
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).
<!--ID: 1717855810790-->
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).
<!--ID: 1717855810794-->
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).
<!--ID: 1717855810798-->
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).
<!--ID: 1717855810802-->
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).

View File

@ -251,7 +251,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi
<!--ID: 1716743248098--> <!--ID: 1716743248098-->
END%% END%%
### Syntactic Identity ## Syntactic Identity
**Syntactic identity** of terms is denoted by "$\equiv$". **Syntactic identity** of terms is denoted by "$\equiv$".
@ -296,7 +296,7 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi
<!--ID: 1717422855722--> <!--ID: 1717422855722-->
END%% END%%
### Length ## Length
The length of a $\lambda$-term (denoted $lgh$) is equal to the number of atoms in the term: 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
<!--ID: 1716743248113--> <!--ID: 1716743248113-->
END%% END%%
### Occurrence ## Occurrence
For $\lambda$-terms $P$ and $Q$, the relation **$P$ occurs in $Q$** is defined by induction on $Q$ as: 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
<!--ID: 1716745016007--> <!--ID: 1716745016007-->
END%% END%%
### Free and Bound Variables ## Free and Bound Variables
An occurrence of a variable $x$ in a term $P$ is called 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
<!--ID: 1716745016034--> <!--ID: 1716745016034-->
END%% 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. 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/x]M \equiv M$
* $x \not\in FV(M) \Rightarrow [N/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\})$ * $x \in FV(M) \Rightarrow FV([N/x]M) = FV(N) \cup (FV(M) - \{x\})$
* $lgh([y/x]M) = lgh(M)$
%%ANKI %%ANKI
Basic Basic
@ -823,38 +824,6 @@ Reference: Hindley, J Roger, and Jonathan P Seldin. “Lambda-Calculus and Combi
<!--ID: 1717439837513--> <!--ID: 1717439837513-->
END%% 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).
<!--ID: 1717449830572-->
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).
<!--ID: 1717449830601-->
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).
<!--ID: 1717449830608-->
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).
<!--ID: 1717449830614-->
END%%
## Bibliography ## 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). * 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).

View File

@ -139,7 +139,7 @@ END%%
%%ANKI %%ANKI
Basic Basic
How does "$P$ if $Q$" translate with $\Rightarrow$? How do you write "$P$ if $Q$" in propositional logic?
Back: $Q \Rightarrow P$ 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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272127--> <!--ID: 1708199272127-->
@ -147,7 +147,23 @@ END%%
%%ANKI %%ANKI
Basic 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).
<!--ID: 1717853966420-->
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).
<!--ID: 1717853966425-->
END%%
%%ANKI
Basic
How do you write "$P$ only if $Q$" in propositional logic?
Back: $P \Rightarrow Q$ 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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272134--> <!--ID: 1708199272134-->
@ -155,7 +171,23 @@ END%%
%%ANKI %%ANKI
Basic 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).
<!--ID: 1717853966429-->
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).
<!--ID: 1717853966432-->
END%%
%%ANKI
Basic
How do you write "$P$ is necessary for $Q$" in propositional logic?
Back: $Q \Rightarrow P$ 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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272140--> <!--ID: 1708199272140-->
@ -163,7 +195,23 @@ END%%
%%ANKI %%ANKI
Basic 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).
<!--ID: 1717853966435-->
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).
<!--ID: 1717853966438-->
END%%
%%ANKI
Basic
How do you write "$P$ is sufficient for $Q$" in propositional logic?
Back: $P \Rightarrow Q$ 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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272145--> <!--ID: 1708199272145-->
@ -171,18 +219,50 @@ END%%
%%ANKI %%ANKI
Basic Basic
Which of *if* or *only if* map to *necessary*? How do you write "$P$ is sufficient for $Q$" using "if"?
Back: *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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272151--> <!--ID: 1717853966441-->
END%% END%%
%%ANKI %%ANKI
Basic Basic
Which of *if* or *only if* map to *sufficient*? How do you write "$P$ is sufficient for $Q$" using "only if"?
Back: *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). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708199272157--> <!--ID: 1717853966444-->
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).
<!--ID: 1717853966449-->
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).
<!--ID: 1717853966454-->
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).
<!--ID: 1717853966458-->
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).
<!--ID: 1717853966462-->
END%% END%%
%%ANKI %%ANKI

View File

@ -480,14 +480,6 @@ Reference: Gries, David. *The Science of Programming*. Texts and Monographs in
<!--ID: 1716310927716--> <!--ID: 1716310927716-->
END%% 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.
<!--ID: 1716310927718-->
END%%
%%ANKI %%ANKI
Basic Basic
*Why* does Distributivity of Disjunction use an implication instead of equality? *Why* does Distributivity of Disjunction use an implication instead of equality?

File diff suppressed because it is too large Load Diff

View File

@ -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.
<!--ID: 1713625933397-->
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.
<!--ID: 1713625933403-->
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.
<!--ID: 1713625933406-->
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.
<!--ID: 1713625933409-->
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.
<!--ID: 1713625933413-->
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.
<!--ID: 1713625933416-->
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.
<!--ID: 1713625933419-->
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.
<!--ID: 1713625933423-->
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.
<!--ID: 1713625933426-->
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.
<!--ID: 1713625933430-->
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.
<!--ID: 1713625933433-->
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.
<!--ID: 1713625933437-->
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.
<!--ID: 1713625933441-->
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.
<!--ID: 1713625933448-->
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.
<!--ID: 1713625933452-->
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.
<!--ID: 1713625933455-->
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.
<!--ID: 1713625933458-->
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.
<!--ID: 1713625933461-->
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.
<!--ID: 1713625933464-->
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.
<!--ID: 1713625933466-->
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.
<!--ID: 1713625933469-->
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.
<!--ID: 1713625933472-->
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.
<!--ID: 1713625933475-->
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.
<!--ID: 1713625933478-->
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.
<!--ID: 1713625933481-->
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.
<!--ID: 1713625933483-->
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.
<!--ID: 1713625933486-->
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.
<!--ID: 1713625933489-->
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.
<!--ID: 1713625933491-->
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
<!--ID: 1714677608754-->
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
<!--ID: 1714677608758-->
END%%
## PUSH and POP
| Instruction | Operands | Effect | Description |
| ----------- | -------- | ------------------------------------------- | -------------- |
| `pushq` | S | R[%rsp] <- R[%rsp] - 8<br />M[R[%rsp]] <- S | Push quad word |
| `popq` | D | D <- M[R[%rsp]]<br />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.
<!--ID: 1715377284944-->
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.
<!--ID: 1715377284947-->
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.
<!--ID: 1715377284951-->
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.
<!--ID: 1715377284955-->
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.
<!--ID: 1715377284959-->
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.
<!--ID: 1715377284962-->
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.
<!--ID: 1715377284966-->
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.
<!--ID: 1715377284971-->
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.
<!--ID: 1715377284975-->
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.
<!--ID: 1715377284980-->
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.
<!--ID: 1715377284985-->
END%%

View File

@ -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.
<!--ID: 1715780601450-->
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.
<!--ID: 1715780601455-->
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
<!--ID: 1715780601458-->
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.
<!--ID: 1715780601461-->
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.
<!--ID: 1715780601464-->
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.
<!--ID: 1715780601467-->
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.
<!--ID: 1715780601469-->
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.
<!--ID: 1715781031929-->
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.
<!--ID: 1715781031935-->
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.
<!--ID: 1715781031938-->
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.
<!--ID: 1715781031941-->
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.
<!--ID: 1716125986895-->
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.
<!--ID: 1716127743477-->
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.
<!--ID: 1716125986904-->
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.
<!--ID: 1716125986907-->
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
<!--ID: 1716126147793-->
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.
<!--ID: 1716125986910-->
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.
<!--ID: 1716127743483-->
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
<!--ID: 1716126147798-->
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.
<!--ID: 1716127743491-->
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.
<!--ID: 1716127743494-->
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.
<!--ID: 1716127743497-->
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
<!--ID: 1716128138030-->
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.
<!--ID: 1716127743500-->
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.
<!--ID: 1716127853102-->
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.
<!--ID: 1716127853106-->
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
<!--ID: 1716128138033-->
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.
<!--ID: 1716127743502-->
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
<!--ID: 1716128138036-->
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.
<!--ID: 1716226827710-->
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.
<!--ID: 1716226827717-->
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.
<!--ID: 1716226827720-->
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.
<!--ID: 1716226827723-->
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.
<!--ID: 1716226827725-->
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.
<!--ID: 1716226827729-->
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.
<!--ID: 1716226827732-->
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.
<!--ID: 1716226827736-->
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.
<!--ID: 1716226827740-->
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.
<!--ID: 1716226827744-->
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.
<!--ID: 1716226827748-->
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.
<!--ID: 1716226827752-->
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.
<!--ID: 1716226827756-->
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.
<!--ID: 1716226827760-->
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.
<!--ID: 1716226827764-->
END%%
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.

View File

@ -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.
<!--ID: 1717941416479-->
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.
<!--ID: 1717941416483-->
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.
<!--ID: 1717941416486-->
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.
<!--ID: 1717941416490-->
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.
<!--ID: 1717941416493-->
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.
<!--ID: 1717941416497-->
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.
<!--ID: 1717941416500-->
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.
<!--ID: 1717941416504-->
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.
<!--ID: 1717941416508-->
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.
<!--ID: 1717941416513-->
END%%
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.

View File

@ -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.
<!--ID: 1710959313804-->
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.
<!--ID: 1710959313810-->
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.
<!--ID: 1710959313814-->
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.
<!--ID: 1710959313818-->
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.
<!--ID: 1710959313822-->
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.
<!--ID: 1710959313826-->
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.
<!--ID: 1713212889887-->
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.
<!--ID: 1713212889894-->
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.
<!--ID: 1713212889897-->
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.
<!--ID: 1713212889901-->
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.
<!--ID: 1713212889905-->
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.
<!--ID: 1713212889909-->
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.
<!--ID: 1713212889912-->
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.
<!--ID: 1713212889916-->
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.
<!--ID: 1713212889920-->
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.
<!--ID: 1713212889923-->
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.
<!--ID: 1713212889927-->
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.
<!--ID: 1713212889930-->
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.
<!--ID: 1713212889933-->
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.
<!--ID: 1713212889937-->
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.
<!--ID: 1713212889941-->
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.
<!--ID: 1713212889945-->
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.
<!--ID: 1713212889949-->
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.
<!--ID: 1713212889952-->
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.
<!--ID: 1713213168875-->
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.
<!--ID: 1713213168878-->
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.
<!--ID: 1713213168881-->
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.
<!--ID: 1713213168884-->
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.
<!--ID: 1713213168887-->
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.
<!--ID: 1713213168890-->
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.
<!--ID: 1713213168894-->
END%%
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.

View File

@ -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.
<!--ID: 1716125986913-->
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.
<!--ID: 1716127743486-->
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
<!--ID: 1716126147801-->
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.
<!--ID: 1716125986916-->
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.
<!--ID: 1716127743488-->
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
<!--ID: 1716126147804-->
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.
<!--ID: 1716381321937-->
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.
<!--ID: 1716127743505-->
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
<!--ID: 1716128138040-->
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.
<!--ID: 1716127743508-->
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
<!--ID: 1716128138043-->
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.
<!--ID: 1716127743511-->
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
<!--ID: 1716128138046-->
END%%
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.

View File

@ -83,6 +83,186 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1713212889874--> <!--ID: 1713212889874-->
END%% 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.
<!--ID: 1717941416520-->
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.
<!--ID: 1717941416525-->
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.
<!--ID: 1717941416529-->
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.
<!--ID: 1717941416534-->
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.
<!--ID: 1717941416539-->
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.
<!--ID: 1717941416543-->
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.
<!--ID: 1717941416548-->
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.
<!--ID: 1717941416552-->
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.
<!--ID: 1717941416558-->
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.
<!--ID: 1717941416565-->
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.
<!--ID: 1717941416572-->
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.
<!--ID: 1717941416578-->
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.
<!--ID: 1717941416584-->
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.
<!--ID: 1717941416588-->
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.
<!--ID: 1717941416592-->
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.
<!--ID: 1717941416597-->
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.
<!--ID: 1717941416601-->
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.
<!--ID: 1717941416605-->
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.
<!--ID: 1717941416609-->
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.
<!--ID: 1717941416613-->
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.
<!--ID: 1717941416617-->
END%%
## Bibliography ## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.