Skip to content

Commit 3a3c6ab

Browse files
committed
CSO Notes update
1 parent 1867a6b commit 3a3c6ab

16 files changed

Lines changed: 655 additions & 279 deletions

notes/courses/CSCI-UA-201/01-num-mem.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Number Systems & Memory Organization
3-
date:
3+
date: 2025-09-02/09
44
---
55

66
## Number system fundamentals
@@ -83,15 +83,12 @@ An $n$-bit quantity can represent $2^n$ distinct values:
8383
- $1$ bit -> $2$ values.
8484
- $8$ bits ($1$ byte) -> $2^8 = 256$ values.
8585

86-
### Text encoding
86+
### Where text and numeric formats live
8787

88-
- **ASCII:** uses $1$ byte ($8$ bits) per character; can encode up to $256$ characters (e.g., `'A' = 65_{10}$).
89-
- **Unicode:** uses $16$ bits or more; supports many languages and symbols ($2^{16}$ or more code points).
88+
This note focuses on bases, units, and memory sizing. For how bits represent:
9089

91-
### Numbers
92-
93-
- **Integers:** stored as binary whole numbers (with specific schemes for signed vs unsigned).
94-
- **Floating-point:** used for real numbers; stored using standardized formats (e.g., IEEE-754) with finite precision, so not all real values can be represented exactly.
90+
- **Text (ASCII, Unicode, UTF-8)**, see **[02 - Data Representation](https://robinc.vercel.app/note.html?course=CSCI-UA-201&note=02-data-repr)**.
91+
- **Signed integers (two's complement)** and **floating point (IEEE 754)**, see **[02 - Data Representation](https://robinc.vercel.app/note.html?course=CSCI-UA-201&note=02-data-repr)**.
9592

9693
## Memory organization
9794

notes/courses/CSCI-UA-201/02-data-repr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Data Representation
3-
date:
3+
date: 2025-09-04
44
---
55

66
## Text and character encoding

notes/courses/CSCI-UA-201/03-c-fund.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: C Programming Fundamentals
3-
date:
3+
date: 2025-09-11
44
---
55

66
## From source code to execution

notes/courses/CSCI-UA-201/04-arrays-ptr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Arrays, Pointers, and Dynamic Memory
3-
date:
3+
date: 2025-09-16/18/23
44
---
55

66
## Stack vs heap memory

notes/courses/CSCI-UA-201/05-ll-bit.md

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,82 @@
11
---
22
title: Linked Lists and Bitwise Operators
3-
date:
3+
date: 2025-09-25/30
44
---
55

6+
## Bitwise operators in C
7+
8+
Integer values are stored as bits. Bitwise operators operate on each bit position.
9+
10+
Assume 8-bit examples for clarity.
11+
12+
### AND `&`
13+
14+
- Result bit is 1 only if both input bits are 1.
15+
16+
Example:
17+
18+
- $00000111_2 \quad \\& \quad 00000100_2 = 00000100_2$
19+
20+
Truth table:
21+
22+
- $0 \\& 0 = 0$
23+
- $0 \\& 1 = 0$
24+
- $1 \\& 0 = 0$
25+
- $1 \\& 1 = 1$
26+
27+
Typical uses:
28+
29+
- Masking to zero out some bits.
30+
- Testing whether specific bits are set.
31+
32+
### OR `|`
33+
34+
- Result bit is 1 if at least one input bit is 1.
35+
36+
Example:
37+
38+
- $00000111_2 \mid 00000100_2 = 00000111_2$
39+
40+
### XOR `^`
41+
42+
- Result bit is 1 if the input bits are different.
43+
44+
Truth table:
45+
46+
- $0 \oplus 0 = 0$
47+
- $0 \oplus 1 = 1$
48+
- $1 \oplus 0 = 1$
49+
- $1 \oplus 1 = 0$
50+
51+
> Using $\oplus$ here means XOR.
52+
53+
Typical uses:
54+
55+
- Flipping bits under a mask.
56+
- Simple parity or checksum calculations.
57+
- Toy "encryption" where the same key applied twice recovers the original.
58+
59+
### NOT `~`
60+
61+
- Flips every bit (0 becomes 1 and 1 becomes 0).
62+
63+
If we consider 8 bits, then
64+
65+
- $\sim 00000101_2 = 11111010_2.$
66+
67+
In two's complement, this is closely related to negation: $-x = \sim x + 1$.
68+
69+
### Shift operators `<<` and `>>`
70+
71+
- `x << k` shifts bits of `x` left by $k$ positions (fills with zeros on the right).
72+
- `x >> k` shifts bits right. For unsigned values this fills with zeros on the left; for signed values it may copy the sign bit.
73+
74+
Shifting left by $k$ is equivalent to multiplying by $2^k$ when there is no overflow.
75+
76+
Example:
77+
78+
- $00000101_2 << 1 = 00001010_2$ which is $5$ shifted to $10$.
79+
680
## Linked lists in C
781

882
A linked list is a dynamic data structure built from nodes that point to one another.
@@ -98,77 +172,3 @@ void print_list(CELL *head) {
98172
- Overwriting `head` while traversing, then losing access to the list.
99173
- Forgetting to initialize `next` for new nodes.
100174
- Failing to `free` nodes eventually, causing memory leaks.
101-
102-
## Bitwise operators in C
103-
104-
Integer values are stored as bits. Bitwise operators operate on each bit position.
105-
106-
Assume 8-bit examples for clarity.
107-
108-
### AND `&`
109-
110-
- Result bit is 1 only if both input bits are 1.
111-
112-
Example:
113-
114-
- $00000111_2 \quad \\& \quad 00000100_2 = 00000100_2$
115-
116-
Truth table:
117-
118-
- $0 \\& 0 = 0$
119-
- $0 \\& 1 = 0$
120-
- $1 \\& 0 = 0$
121-
- $1 \\& 1 = 1$
122-
123-
Typical uses:
124-
125-
- Masking to zero out some bits.
126-
- Testing whether specific bits are set.
127-
128-
### OR `|`
129-
130-
- Result bit is 1 if at least one input bit is 1.
131-
132-
Example:
133-
134-
- $00000111_2 \mid 00000100_2 = 00000111_2$
135-
136-
### XOR `^`
137-
138-
- Result bit is 1 if the input bits are different.
139-
140-
Truth table:
141-
142-
- $0 \oplus 0 = 0$
143-
- $0 \oplus 1 = 1$
144-
- $1 \oplus 0 = 1$
145-
- $1 \oplus 1 = 0$
146-
147-
> Using $\oplus$ here means XOR.
148-
149-
Typical uses:
150-
151-
- Flipping bits under a mask.
152-
- Simple parity or checksum calculations.
153-
- Toy "encryption" where the same key applied twice recovers the original.
154-
155-
### NOT `~`
156-
157-
- Flips every bit (0 becomes 1 and 1 becomes 0).
158-
159-
If we consider 8 bits, then
160-
161-
- $\sim 00000101_2 = 11111010_2.$
162-
163-
In two's complement, this is closely related to negation: $-x = \sim x + 1$.
164-
165-
### Shift operators `<<` and `>>`
166-
167-
- `x << k` shifts bits of `x` left by $k$ positions (fills with zeros on the right).
168-
- `x >> k` shifts bits right. For unsigned values this fills with zeros on the left; for signed values it may copy the sign bit.
169-
170-
Shifting left by $k$ is equivalent to multiplying by $2^k$ when there is no overflow.
171-
172-
Example:
173-
174-
- $00000101_2 << 1 = 00001010_2$ which is $5$ shifted to $10$.

notes/courses/CSCI-UA-201/06-cli-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Command-Line Arguments and File I/O
3-
date:
3+
date: 2025-10-30/11-06
44
---
55

66
## Command-line arguments

notes/courses/CSCI-UA-201/07-asm-intro.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Introduction to Assembly Language
3-
date:
3+
date: 2025-10-23
44
---
55

66
## CPU registers
@@ -50,29 +50,24 @@ Read `mov S, D` as "move S into D".
5050

5151
## Core instructions
5252

53-
### MOV (copy data)
53+
### MOV (copy data, brief)
5454

5555
```asm
5656
mov SOURCE, DEST
5757
```
5858

59-
- Copies data from `SOURCE` into `DEST`.
60-
- The source is not changed.
59+
- Copies data from `SOURCE` into `DEST` (the source is not changed).
60+
- Operand order is `source, destination` in AT&T syntax.
6161

62-
Example:
63-
64-
```asm
65-
mov $25, %rax
66-
mov %rax, %rbx
67-
```
68-
69-
Common mistake: leaving out `$` for immediates:
62+
Common pitfall (immediate vs address):
7063

7164
```asm
7265
mov 25, %rax # WRONG: uses address 25
7366
mov $25, %rax # RIGHT: literal 25
7467
```
7568

69+
For the full set of `mov` forms (memory dereference, offsets, base/index/scale) and array/struct addressing, see **08**.
70+
7671
### ADD and SUB
7772

7873
```asm
Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Move Instructions, Addressing, and Calling Conventions
3-
date:
2+
title: Move Instructions and Addressing Modes
3+
date: 2025-10-28/30
44
---
55

66
## Move instructions and data movement
@@ -95,103 +95,4 @@ Given a pointer to `struct student` in `%rsi` and index `i` in `%rcx`, `grades[i
9595
- plus `i * 4` (size of each `int`),
9696

9797
which matches `mov 12(%rsi, %rcx, 4), %rax`.
98-
99-
## Calling conventions
100-
101-
### Caller-saved and callee-saved registers
102-
103-
Registers are grouped according to who must preserve them across function calls.
104-
105-
- Caller-saved registers (scratch):
106-
- `RAX`, `RCX`, `RDX`, `RDI`, `RSI`, `R8`, `R9`, `R10`, `R11`.
107-
- A callee is allowed to overwrite these.
108-
- If the caller needs their values later, the caller must save and restore them.
109-
110-
- Callee-saved registers (preserved):
111-
- `RBX`, `RBP`, `R12`, `R13`, `R14`, `R15`.
112-
- If a function uses any of these, it must save the old value (usually with `push`) and restore it before returning.
113-
114-
### Function parameters and return values
115-
116-
For integer and pointer parameters, the System V x86-64 convention passes the first six arguments in registers:
117-
118-
1. `RDI`
119-
2. `RSI`
120-
3. `RDX`
121-
4. `RCX`
122-
5. `R8`
123-
6. `R9`
124-
125-
Additional arguments are pushed on the stack by the caller from right to left.
126-
127-
The return value is placed in `RAX`.
128-
129-
Example call:
130-
131-
```asm
132-
mov $10, %rdi # arg1
133-
mov $20, %rsi # arg2
134-
mov $30, %rdx # arg3
135-
mov $40, %rcx # arg4
136-
mov $50, %r8 # arg5
137-
mov $60, %r9 # arg6
138-
push $80 # arg8 (pushed first)
139-
push $70 # arg7 (pushed second)
140-
call g
141-
```
142-
143-
Inside `g`, the parameters appear in the same registers and the extra ones are on the stack.
144-
145-
### Function prologue and epilogue
146-
147-
Standard function layout:
148-
149-
```asm
150-
.globl f
151-
f:
152-
# prologue
153-
push %rbp
154-
mov %rsp, %rbp
155-
156-
# optionally save callee-saved registers, for example:
157-
# push %rbx
158-
159-
# body
160-
161-
# restore callee-saved registers if saved:
162-
# pop %rbx
163-
164-
# epilogue
165-
pop %rbp
166-
ret
167-
```
168-
169-
- The prologue creates a new stack frame with `RBP` as a stable base pointer.
170-
- The epilogue restores the old base pointer and returns to the caller.
171-
172-
### Simple example
173-
174-
C code:
175-
176-
```c
177-
int add_5(int a) {
178-
return a + 5;
179-
}
180-
```
181-
182-
Assembly:
183-
184-
```asm
185-
.globl add_5
186-
add_5:
187-
push %rbp
188-
mov %rsp, %rbp
189-
190-
mov $5, %rax # RAX = 5
191-
add %rdi, %rax # RAX = a + 5 (a is in RDI)
192-
193-
pop %rbp
194-
ret # result is in RAX
195-
```
196-
197-
This respects the register and calling conventions and computes the sum correctly.
98+
For calling conventions (arg registers, caller/callee-saved, stack frames, prologue/epilogue), see **[09 - Function Conventions and Cache Basics](https://robinc.vercel.app/note.html?course=CSCI-UA-201&note=09-func-cache)**.

0 commit comments

Comments
 (0)