๐ -> 11/27/24: ECS50-L25
[Lecture Slide Link]
๐ค Vocab
โ Unit and Larger Context
Final Review Topics
- Itโs all bits
- Bitwise operators
- How many bits needed to represent
- With B bits
- Unsigned, Sign magnitude, 2s complement
- Floatign point
- Hex
- Covnerting Between bases
- Structus
- Arrays, multidimensional
- Debugging
- Assembly / Intel cheat sheet
- Advanced indexing (accessing memory)
- leal
- Advanced indexing (accessing memory)
- GCC calling conventions
- Components of computer
- Components of computer
- Why programs arenโt portable
- Inline assembly
- Stack and Stack frames
- Prologue and epilogue
- I/O
- Polling vs interrupt driven I/O
- Memory mapped vs I/O mapped
- Interrupts
- OS
- What does it do
- Applications loaded
- Bootloader an how it loads the OS
- Time sharing
- System calls
- Parallelism pipelining
- Programmer: Message passing or shared memory
- Instructions are represented with bits
- Internals of representation
โ๏ธ -> Scratch Notes
Linux System Call Tables
int $0x80 system calls
Virtual Memory
- Notice how no matter how many times you run a program, you always have the same pointer values, the same โaddressesโ
- On creating an application, given virtual memory
- Allocated in โblocksโ
- Wonโt go past block with a +1 error, only seg faults (going past allocated block) when you go significantly past your block
Printing From Assembly
fun(int a, int b, int c) {
int x, y, z;
p ((int *)$ebp)[2]@3 # print args
p ((int *)$ebp)[-3]@3 # print locals
}
Midterm 2 Review
- CPU instructions
100,000 * 4 / 50,000
- Conflicting compiler instructions
jb/jae or jl/jge
Don't know how to compare signed and unsigned
- Just push, pop, and call manually
praerielearn
- 1 GDB command to print out the value before it returns
p $eax
- Allocating space for program
same as praerielearn, instruction / data or text
- Which parts are part of the stack
everything greater or equal than ESP pointing to
- Save registers? Minimal set for callee
Caller:
- Save only ACD
Callee:
- Save everything but ACD
ESP is weird, left off the exam
- Consider it Callee saved
- Write down the component name
Instruction - IR
Address of instruct - PC
Communicate - BUS
MAR
MDR
Arithmatetic - ALU
Stores running data - Memory
Points to top of stack - ESP
- Whats in MAR and MDR?
movl %eax, %ebx:
- MAR: No Value
- MDR: No Value
push %edx:
- MAR: 996 (subtract 4 from 1000)
- MDR: 50(value pushed)
movl 400(%eax, %edx, 4), %ecx:
- MAR: 1600 (value computed)
- MDR: -786 (value at 1600)
ret
- MAR: 1000 (the memory popped from)
- MDR: 255 (the value popped)
movw $77, ($ebp)
- MAR: 200
- MDR: 77
pop %ecx
- 1000
- 255
movb (%esi, %ebx), %dh
- 3100
- Unknown (past addresses shown)
Inline Assembly
bextr - Bit extraction?
bextr.cpp
unsigned int get_bits(int from, int start, int end) {
int num_bits = end - start + 1;
unsigned result;
__asm__(
//code
"movb ch"
"movb cl"
"bextr %%ecx, %[from], %[result]"
:
//outputs
[result] "=r" (result)
:
//inputs
[from] "r" (from), [start]"b"(start), [amount] "a" (num_bits)
:
//clobbering
"cc", "%ecx"
);
}
int main() {
unsigned int val = 0b011 1011 1101 1101;
unsigned int bits = get_bits(val, 4, 9);
printf("%x\n", bits); // prints 1D
return 0;
}๐ -> Links
Resources
- Put useful links here
Connections
- Link all related words