Notes on frame pointers.
parent
bb6343317d
commit
ee6d3d8493
|
@ -526,7 +526,7 @@
|
|||
"set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7",
|
||||
"_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
|
||||
"_journal/2024-05/2024-05-13.md": "d549dd75fb42b4280d4914781edb0113",
|
||||
"x86-64/registers.md": "a1daead80c55434c0aed939c53103f9d",
|
||||
"x86-64/registers.md": "5fc70aaebf9dc7d4b04c72650bedacfe",
|
||||
"_journal/2024-05-15.md": "4e6a7e6df32e93f0d8a56bc76613d908",
|
||||
"_journal/2024-05/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
|
||||
"_journal/2024-05-16.md": "580c7ec61ec56be92fa8d6affcf0a5f6",
|
||||
|
@ -593,9 +593,9 @@
|
|||
"lambda-calculus/alpha-conversion.md": "6df655e60976715e5c6fbbe72b628c6d",
|
||||
"lambda-calculus/index.md": "0e47dcd2ac0c84ad4c1a5e7609dade5f",
|
||||
"x86-64/instructions/condition-codes.md": "9c05ed99f5c96162e25f0ec4db55c656",
|
||||
"x86-64/instructions/logical.md": "49d40018f1fcb4ed1595d9175bbaab57",
|
||||
"x86-64/instructions/arithmetic.md": "df57fdc8d260d0812464b08565ef4c51",
|
||||
"x86-64/instructions/access.md": "4589d79f9915ffeeab7b75d2208b7917",
|
||||
"x86-64/instructions/logical.md": "a15c7da43cb97badef8ba4f8aadf9cbb",
|
||||
"x86-64/instructions/arithmetic.md": "e2c4c9caa51e089e313d6c9d3c3c0a12",
|
||||
"x86-64/instructions/access.md": "e5a282c053019fc63df5114b1c052c2f",
|
||||
"x86-64/instructions/index.md": "cc5505d01d8409255fa42e87bfe15f07",
|
||||
"_journal/2024-06-09.md": "935b3ddf65c51e680ac5c000c7e380af",
|
||||
"_journal/2024-06/2024-06-08.md": "9e1ebc8882a395b96ca765ad5c982d68",
|
||||
|
@ -798,7 +798,7 @@
|
|||
"c17/basic-types.md": "7c6653bf6dc24c2f2aa72fc95c4f7875",
|
||||
"c17/types/simple.md": "44d56a2998f3bba578f14672c8b0ee3c",
|
||||
"c17/types/enumerated.md": "e1f70a30677c776b7b44ac3e0ff4e76d",
|
||||
"c17/types/derived.md": "7e5d0939f72ee02ae00a78a2af17a0fd",
|
||||
"c17/types/derived.md": "26bcaee99aba7720fd76d92e10770933",
|
||||
"c17/types/basic.md": "5064e21e683c0218890058882e06b6f3",
|
||||
"c17/types/index.md": "14b651bcfc8b2d62ffd200a74a9a2a6b",
|
||||
"_journal/2024-08-25.md": "e73a8edbd027d0f1a39289540eb512f2",
|
||||
|
@ -879,9 +879,9 @@
|
|||
"_journal/2024-10/2024-10-06.md": "65a8e538144f59ee9e7296110cc9aa14",
|
||||
"_journal/2024-10-09.md": "66acb6c8abbf0c860966223f3299c2bc",
|
||||
"_journal/2024-10/2024-10-08.md": "2f737d8198b12bf635808964c4887ae1",
|
||||
"x86-64/procedures.md": "3464bb6229f85973961c6693f47d6f20",
|
||||
"x86-64/procedures.md": "4f8bb79e11b710eaccaf7ecb847bd69f",
|
||||
"_journal/2024-10-10.md": "29e4be2c164c63f8b7aab56bddee3dd6",
|
||||
"_journal/2024-10/2024-10-09.md": "b718c6f4cfe3069fcc0faf07ec414f73",
|
||||
"_journal/2024-10/2024-10-09.md": "458811cdab772a7b3dbc1dd8ae5c51ee",
|
||||
"_journal/2024-10-15.md": "6e696a8d16ba257ed89e8564b771d290",
|
||||
"_journal/2024-10/2024-10-14.md": "fbb5a82a18e3acca55bb46a824a9419d",
|
||||
"_journal/2024-10/2024-10-13.md": "8882c01060a4a909fd890180db356e73",
|
||||
|
@ -940,7 +940,8 @@
|
|||
"_journal/2024-11/2024-11-13.md": "db4f2e5db5bb1d2199fee88eb1a6c881",
|
||||
"_journal/2024-11/2024-11-12.md": "24c858a93c0a5063820bd96207e6f8ab",
|
||||
"_journal/2024-11/2024-11-11.md": "d3ad8ddc5ecdb2cc08773fdef2ce6869",
|
||||
"_journal/2024-11/2024-11-10.md": "38ce405754e3823c8239df44546f3b35"
|
||||
"_journal/2024-11/2024-11-10.md": "38ce405754e3823c8239df44546f3b35",
|
||||
"x86-64/instructions/procedures.md": "fd83b80e35454d4bca12c4cf8127cf91"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -8,4 +8,4 @@ title: "2024-10-09"
|
|||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
|
||||
* Start adding notes on [[procedures]].
|
||||
* Start adding notes on [[x86-64/procedures]].
|
|
@ -7,3 +7,5 @@ title: "2024-11-18"
|
|||
- [ ] OGS
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
|
||||
* Notes on [[x86-64/procedures#Frame Pointer|frame pointers]].
|
|
@ -40,7 +40,7 @@ END%%
|
|||
|
||||
### Arrays
|
||||
|
||||
An array is a contiguous sequence of objects. An array is either a **fixed-length array** (FLA) or a **variable-length array** (VLA).
|
||||
An array is a contiguous sequence of objects. An array is either a **fixed-length array** or a **variable-length array**.
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
|
@ -155,114 +155,6 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co
|
|||
<!--ID: 1727957575990-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Where *must* a VLA be declared?
|
||||
Back: Within a function.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957575996-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two ways can the length of an FLA be specified?
|
||||
Back: By an ICE or an initializer.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576002-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[4];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576008-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[];
|
||||
```
|
||||
Back: N/A. This is invalid syntax.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576013-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[] = { 0 };
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576019-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
int n = 2;
|
||||
double a[n];
|
||||
```
|
||||
Back: VLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576025-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
#define n 2
|
||||
double a[n];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576030-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
enum { n = 2 };
|
||||
double a[n];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576036-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
int n = 2;
|
||||
double a[n] = {0};
|
||||
```
|
||||
Back: N/A. This is an invalid assignment.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576041-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
For the following to be an FLA, what must `N` be?
|
||||
```c
|
||||
double a[N];
|
||||
```
|
||||
Back: An ICE.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576047-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Replace `EXPR` in the following with an expression to compute the length of `A`.
|
||||
|
@ -555,6 +447,165 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co
|
|||
<!--ID: 1730758755493-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[4];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576008-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[];
|
||||
```
|
||||
Back: N/A. This is invalid syntax.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576013-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
double a[] = { 0 };
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576019-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
int n = 2;
|
||||
double a[n];
|
||||
```
|
||||
Back: VLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576025-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
#define n 2
|
||||
double a[n];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576030-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
enum { n = 2 };
|
||||
double a[n];
|
||||
```
|
||||
Back: FLA.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576036-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Is the following an FLA or VLA?
|
||||
```c
|
||||
int n = 2;
|
||||
double a[n] = {0};
|
||||
```
|
||||
Back: N/A. This is an invalid assignment.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576041-->
|
||||
END%%
|
||||
|
||||
#### Fixed-Length
|
||||
|
||||
A fixed-length array (FLA) has a predetermined size. Their stack allocations can be computed at compilation time.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is FLA an acronym for?
|
||||
Back: **F**ixed-**l**ength **a**rray.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634166-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two ways can the length of an FLA be specified?
|
||||
Back: By an ICE or an initializer.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576002-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
For the following to be an FLA, what must `N` be?
|
||||
```c
|
||||
double a[N];
|
||||
```
|
||||
Back: An ICE.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957576047-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* must FLAs be declared within a function?
|
||||
Back: N/A. They can exist elsewhere.
|
||||
Tags: x86-64
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634167-->
|
||||
END%%
|
||||
|
||||
#### Variable-Length
|
||||
|
||||
A variable-length array (VLA) has its size determined at runtime. Their stack allocations must be determined with respect to other registers available to the frame.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is VLA an acronym for?
|
||||
Back: **V**ariable-**l**ength **a**rray.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634168-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Where *must* a VLA be declared?
|
||||
Back: Within a function.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
<!--ID: 1727957575996-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* do variable-length arrays require use of a frame pointer?
|
||||
Back: Offsets depend on how much space must be allocated on the stack.
|
||||
Tags: x86-64
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634169-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* must VLAs be declared within a function?
|
||||
Back: Their implementation relies on frame pointers.
|
||||
Tags: x86-64
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634170-->
|
||||
END%%
|
||||
|
||||
### Structures
|
||||
|
||||
A `struct` is a grouping of data together. It has the following general form:
|
||||
|
|
|
@ -320,10 +320,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What equivalent no-operand instruction does x86-64 provide?
|
||||
```asm
|
||||
movslq %eax, %rax
|
||||
```
|
||||
How is `movslq %eax, %rax` equivalently written using a single no-operand instruction?
|
||||
Back: `cltq`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728382784107-->
|
||||
|
@ -331,10 +328,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What equivalent no-operand instruction does x86-64 provide?
|
||||
```asm
|
||||
movzlq %eax, %rax
|
||||
```
|
||||
How is `movzlq %eax, %rax` equivalently written using a single no-operand instruction?
|
||||
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: 1728479148446-->
|
||||
|
@ -396,8 +390,8 @@ Basic
|
|||
How is `pushq %rbp` equivalently written using a pair of instructions?
|
||||
Back:
|
||||
```asm
|
||||
subq $8,%rsp
|
||||
movq %rbp,(%rsp)
|
||||
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-->
|
||||
|
@ -408,8 +402,8 @@ Basic
|
|||
How is `popq %rax` equivalently written using a pair of instructions?
|
||||
Back:
|
||||
```asm
|
||||
movq (%rsp),%rax
|
||||
addq $8,%rsp
|
||||
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-->
|
||||
|
@ -448,8 +442,12 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the `%rsp` register typically used for?
|
||||
Back: The stack pointer.
|
||||
Why is register `%rsp` named the way it is?
|
||||
Back: It stands for **s**tack **p**ointer.
|
||||
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%%
|
||||
|
||||
## Bibliography
|
||||
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
|
@ -6,7 +6,7 @@ tags:
|
|||
- x86-64
|
||||
---
|
||||
|
||||
### Load Effective Address
|
||||
### LEAQ
|
||||
|
||||
| Instruction | Operands | Effect | Description |
|
||||
| ----------- | -------- | ------- | ---------------------- |
|
||||
|
@ -237,7 +237,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which `SUB` instruction is equivalent to `decq %rcx`?
|
||||
How is `decq %rcx` equivalently written using the `SUB` instruction class?
|
||||
Back:
|
||||
```asm
|
||||
subq $1, %rcx
|
||||
|
|
|
@ -8,10 +8,10 @@ tags:
|
|||
|
||||
### Unary Operations
|
||||
|
||||
| Instruction | Operands | Effect | Description |
|
||||
| ----------- | -------- | ---------- | ----------- |
|
||||
| `neg[bwlq]` | D | D <- -D | Negate |
|
||||
| `not[bwlq]` | D | D <- ~D | Complement |
|
||||
| Instruction | Operands | Effect | Description |
|
||||
| ----------- | -------- | ------- | ----------- |
|
||||
| `neg[bwlq]` | D | D <- -D | Negate |
|
||||
| `not[bwlq]` | D | D <- ~D | Complement |
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
---
|
||||
title: Procedures
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: x86-64
|
||||
tags:
|
||||
- x86-64
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The details of procedures are detailed in [[x86-64/procedures|procedures]]. This file touches on the most relevant instruction classes.
|
||||
|
||||
## CALL and RET
|
||||
|
||||
Like [[conditions#JMP|JMP]] instructions, `call` allows specifying a direct or indirect operand. `call` pushes the address of the instruction following it onto the stack and updates the PC to the operand. `ret` reverts these steps.
|
||||
|
||||
| Instruction | Operands | Description |
|
||||
| ----------- | ----------- | ---------------- |
|
||||
| `call` | Label | Procedure call |
|
||||
| `call` | \**Operand* | Procedure call |
|
||||
| `ret` | | Return from call |
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`call`} instruction is the counterpart to the {`ret`} instruction.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288130-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two things does the `call` instruction do?
|
||||
Back: It pushes the return address on the stack and updates the PC.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288148-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two things does the `ret` instruction do?
|
||||
Back: It pops the return address off the stack and updates the PC.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288160-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `ret` equivalently written using a line of assembly?
|
||||
Back:
|
||||
```asm
|
||||
popq %rip
|
||||
```
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634162-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
The operand forms of `call` mirror what other instruction class?
|
||||
Back: `JMP`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288165-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
A `call` instruction pushes what address onto the stack?
|
||||
Back: That of the instruction following the `call` instruction.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288171-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What return address is pushed onto the stack after `call` is run?
|
||||
```x86
|
||||
1: ...
|
||||
2: callq .L1
|
||||
3: ...
|
||||
```
|
||||
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: 1728558288177-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What address is the PC updated to after `call` is run?
|
||||
```x86
|
||||
1: ...
|
||||
2: callq .L1
|
||||
3: ...
|
||||
```
|
||||
Back: That corresponding to label `.L1`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288183-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which register(s) does a `call` instruction update?
|
||||
Back: `%rsp` and `%rip`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728559336730-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which register(s) does a `ret` instruction update?
|
||||
Back: `%rsp` and `%rip`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728559336760-->
|
||||
END%%
|
||||
|
||||
## LEAVE
|
||||
|
||||
`leave` parallels the `ret` instruction. It is equivalent to the following two instructions:
|
||||
|
||||
```asm
|
||||
movq %rbp, %rsp
|
||||
popq %rbp
|
||||
```
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two things does the `leave` instruction do?
|
||||
Back: Restores the stack pointer and pops off the caller-saved base pointer.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634163-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `leave` equivalently written using a pair of instructions?
|
||||
Back:
|
||||
```asm
|
||||
movq %rbp, %rsp
|
||||
popq %rbp
|
||||
```
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634164-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Fixed-sized frames use which of `leave` and/or `ret`?
|
||||
Back: Just `ret`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952715097-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Variable-sized frames use which of `leave` and/or `ret`?
|
||||
Back: Bot
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952715103-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
{1:`ret`} is to {2:`%rsp`} whereas {2:`leave`} is to {1:`%rbp`}.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634165-->
|
||||
END%%
|
||||
|
||||
## Bibliography
|
||||
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
|
@ -134,100 +134,7 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1730121604407-->
|
||||
END%%
|
||||
|
||||
## CALL and RET
|
||||
|
||||
Like [[conditions#JMP|JMP]] instructions, `call` allows specifying a direct or indirect operand. `call` pushes the address of the instruction following it onto the stack and updates the PC to the operand. `ret` reverts these steps.
|
||||
|
||||
| Instruction | Operands | Description |
|
||||
| ----------- | ----------- | ---------------- |
|
||||
| `call` | Label | Procedure call |
|
||||
| `call` | \**Operand* | Procedure call |
|
||||
| `ret` | | Return from call |
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`call`} instruction is the counterpart to the {`ret`} instruction.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288130-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two things does the `call` instruction do?
|
||||
Back: It pushes the return address on the stack and updates the PC.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288148-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two things does the `ret` instruction do?
|
||||
Back: It pops the return address off the stack and updates the PC.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288160-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
The operand forms of `call` mirror what other instruction class?
|
||||
Back: `JMP`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288165-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
A `call` instruction pushes what address onto the stack?
|
||||
Back: That of the instruction following the `call` instruction.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288171-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What return address is pushed onto the stack after `call` is run?
|
||||
```x86
|
||||
1: ...
|
||||
2: callq .L1
|
||||
3: ...
|
||||
```
|
||||
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: 1728558288177-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What address is the PC updated to after `call` is run?
|
||||
```x86
|
||||
1: ...
|
||||
2: callq .L1
|
||||
3: ...
|
||||
```
|
||||
Back: That corresponding to label `.L1`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728558288183-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which register(s) does a `call` instruction update?
|
||||
Back: `%rsp` and `%rip`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728559336730-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which register(s) does a `ret` instruction update?
|
||||
Back: `%rsp` and `%rip`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1728559336760-->
|
||||
END%%
|
||||
|
||||
## Local Storage
|
||||
|
||||
### On the Stack
|
||||
## Local Variables
|
||||
|
||||
x86-64 employs 6 registers for passing integral (i.e. integer and pointer) arguments between caller and callee.
|
||||
|
||||
|
@ -633,7 +540,7 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1730120207052-->
|
||||
END%%
|
||||
|
||||
### In Registers
|
||||
## Callee-Saved Registers
|
||||
|
||||
x86-64 employs 6 registers as callee-saved registers. If procedure `P` calls procedure `Q`, `Q` *must* preserve the values of these registers. That is, if `Q` were to modify these registers, `Q` is also responsible for restoring these values before returning back to `P`.
|
||||
|
||||
|
@ -660,6 +567,14 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1730121604414-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which registers are designated as caller-saved?
|
||||
Back: All but callee-saved registers and `%rsp`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731946757133-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*What* is a callee-saved register?
|
||||
|
@ -691,6 +606,153 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1730121604434-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are used for passing integral arguments to procedures?
|
||||
Back: `%r8` and `%r9`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810848-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are conventionally designated "callee-saved"?
|
||||
Back: `%r12`, `%13`, `%r14`, and `%r15`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810852-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are conventionally designated "caller-saved"?
|
||||
Back: `%r10` and `%r11`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810854-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does it mean for a register to be callee-saved?
|
||||
Back: The callee must ensure the register's value is unchanged by the time it returns.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810857-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does it mean for a register to be caller-saved?
|
||||
Back: Any procedure can modify the register's value.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810860-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* are caller-saved registers named the way they are?
|
||||
Back: It's up to the caller to preserve their value before a procedure call.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810863-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What misnomer does designating `%r10` and `%r11` as caller-saved registers introduce?
|
||||
Back: This seems to imply there are no other caller-saved registers.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731946757135-->
|
||||
END%%
|
||||
|
||||
## Frame Pointer
|
||||
|
||||
The **frame pointer**, also known as the **base pointer**, marks the start of a variable-sized frame. `%rbp` is pushed onto the stack (since it is caller-saved) and its value updated to the new value of `%rsp`. Relative offsets are then computed according to it.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why is register `%rbp` named the way it is?
|
||||
Back: It stands for **b**ase **p**ointer.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634150-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
{1:`%rsp`} is to {2:fixed}-sized frames whereas {2:`%rbp`} is to {1:variable}-sized frames.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634151-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When is the `%rbp` register used?
|
||||
Back: When working with variable-sized frames.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634153-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In fixed-sized frames, what is the first callee-saved register on the stack?
|
||||
Back: Indeterminate.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634154-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In variable-sized frames, what is the first callee-saved register on the stack?
|
||||
Back: `%rbp`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634155-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is typically the ultimate instruction of a fixed-sized frame?
|
||||
Back: `ret`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634156-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is typically the penultimate instruction of a fixed-sized frame?
|
||||
Back: Indeterminate.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634157-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is typically the ultimate instruction of a variable-sized frame?
|
||||
Back: `ret`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634158-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is typically the penultimate instruction of a variable-sized frame?
|
||||
Back: `leave`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634159-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Assume frame `Q` starts at address `S`. If applicable, what address is its frame pointer set to?
|
||||
Back: `S + 8`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634160-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Assume frame `Q` starts at address `S`. When applicable, *why* is `%rbp` set to `S + 8`?
|
||||
Back: It's the value of `%rsp` after pushing the previous value of `%rbp`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731952634161-->
|
||||
END%%
|
||||
|
||||
## Bibliography
|
||||
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
|
|
|
@ -309,50 +309,10 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are used for passing integral arguments to procedures?
|
||||
Back: `%r8` and `%r9`.
|
||||
What misnomer does designating registers for a certain purpose introduce?
|
||||
Back: Designations are convention-based. Registers can be used for any purpose.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810848-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are conventionally designated "callee-saved"?
|
||||
Back: `%r12`, `%13`, `%r14`, and `%r15`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810852-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which number-suffixed register(s) are conventionally designated "caller-saved"?
|
||||
Back: `%r10` and `%r11`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810854-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does it mean for a register to be callee-saved?
|
||||
Back: The callee must ensure the register's value is unchanged by the time it returns.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810857-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does it mean for a register to be caller-saved?
|
||||
Back: Any procedure can modify the register's value.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810860-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* are caller-saved registers named the way they are?
|
||||
Back: It's up to the caller to preserve their value before a procedure call.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1731938810863-->
|
||||
<!--ID: 1731946757131-->
|
||||
END%%
|
||||
|
||||
## Condition Codes
|
||||
|
|
Loading…
Reference in New Issue