Share
Embed
Transcript
66 slides
-
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Control Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
David Wheeler “All problems in computer science can be solved
by another level of indirection, except of course for the problem of too many indirections.” -
This stuff is cool, but you don’t need to think
about it every day. Unless you do. -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Control Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
Boolean Logic Algebra • 0 & 1, false & true,
off & on • AND, OR, XOR, NOT • NAND, NOR -
Boolean Logic • Send power to the ECU if the
ignition is in “ON” OR “START” • Turn on the stairway lights if the bottom switch XOR the top switch are up • Trigger the hydraulic press if the left hand button AND the right hand button are pressed. -
Half Adder Output 1 if the left input is 1
XOR the right input is 1 Carry 1 if the left input is 1 AND the right input is 1 -
Half Adder Inputs Outputs A B C S 0 0
0 0 1 0 0 1 0 1 0 1 1 1 1 0 -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Logic Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
Arithmetic & Logic Units • Boolean logic units: AND, OR,
XOR, etc. • Integer Arithmetic: addition, multiplication, division • Floating-point Arithmetic: addition, multiplication, division -
Full Adder • Inputs: • Operand (1-bit) • Operand (1-bit)
• Carry Operand (1-bit) • Outputs: • Result (1-bit) • Carry Result (1- bit) -
Arithmetic Logic Unit • Inputs: • Operand (n-bit) • Operand
(n-bit) • Operator Picker • Outputs: • Result (n-bit) -
Building an ALU • Get adders, multipliers, boolean units •
Use a multiplexer to pick different operations -
Building a Calculator • Buttons to enter operands • Buttons
to pick an operation • Button to show results • Memory • Decimal-to-binary circuit -
Arithmetic Logic Unit • Inputs: • Operand (n-bit) • Operand
(n-bit) • Operator Picker • Outputs: • Result (n-bit) -
Operand (8-bit) Operand (8-bit) Operator Picker (8-bit) Destination (8-bit) Operation
Operand Operand Destination 8 bits 8 bits 8 bits 8 bits Logic multiplexer Input A Input B Output Multiplexer -
MIPS Instruction Format Copyright 2009 by Elsevier, Inc., All rights
reserved. From Patterson and Hennessy, Computer Organization and Design, 4th ed. -
It would be cool if we could chain up operations
and store results somewhere -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Logic Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
Registers • Wired in right next to the logic units
• Short wires mean fast • Short wires mean you can’t have very many • This computer has sixteen 64-bit registers -
Random Access Memory • Ask for an address, get a
value • Ask to put a value in to an address • Long wires mean slow and cheap • This computer has 8GB, or 1,073,741,824 registers worth -
Memory Hierarchy • Register: keeping a number in your head
while you do math on paper • RAM: keeping a number in a file cabinet in the other room while you do math on paper -
Cache • Faster than memory, bigger than registers • Multiple
levels, L1, L2, … • Lower levels faster but smaller • Cache invalidation -
Memory Hierarchy • Register: keeping a number in your head
• L1 Cache: jotting a number down on paper • L2 Cache: putting that paper in a pile • L3 Cache: putting that pile in a folder • RAM: a file cabinet in the other room -
Virtual Memory Automatically moving file cabinets from the other room
to a storage facility on the Moon (disk is slow, and huge) -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Logic Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
MIPS Instruction Format Copyright 2009 by Elsevier, Inc., All rights
reserved. From Patterson and Hennessy, Computer Organization and Design, 4th ed. -
> otool -t /bin/ls /bin/ls: (__TEXT,__text) section 00000001000010f8 55 48
89 e5 48 83 c7 68 48 83 c6 68 5d e9 50 35 0000000100001108 00 00 55 48 89 e5 48 8d 46 68 48 8d 77 68 48 89 0000000100001118 c7 5d e9 3b 35 00 00 55 48 89 e5 48 8b 4f 60 4c 0000000100001128 8b 41 30 48 8b 56 60 b8 01 00 00 00 4c 39 42 30 0000000100001138 7f 1a 7d 07 b8 ff ff ff ff eb 11 48 8b 49 38 48 0000000100001148 39 4a 38 7f 07 b8 ff ff ff ff 7d 02 5d c3 48 83 0000000100001158 c7 68 48 83 c6 68 5d e9 f6 34 00 00 55 48 89 e5 0000000100001168 48 89 f9 48 8b 51 60 4c 8b 42 30 48 8b 7e 60 b8 0000000100001178 ff ff ff ff 4c 39 47 30 7f 1a 7d 07 b8 01 00 00 0000000100001188 00 eb 11 48 8b 52 38 48 39 57 38 7f 07 b8 01 00 0000000100001198 00 00 7d 02 5d c3 48 83 c6 68 48 83 c1 68 48 89 00000001000011a8 f7 48 89 ce 5d e9 a8 34 00 00 55 48 89 e5 48 8b 00000001000011b8 4f 60 4c 8b 41 20 48 8b 56 60 b8 01 00 00 00 4c 00000001000011c8 39 42 20 7f 1a 7d 07 b8 ff ff ff ff eb 11 48 8b -
"Altair 8800 at the Computer History Museum, cropped" by Todd
Dailey - File:Altair 8800 at the Computer History Museum.jpg (cropped; curves; contrast). Licensed under Creative Commons Attribution-Share Alike 2.0 via Wikimedia Commons - http:/ /commons.wikimedia.org/wiki/ File:Altair_8800_at_the_Computer_History_Museum,_cropped.jpg#media viewer/File:Altair_8800_at_the_Computer_History_Museum,_cropped.jpg -
> otool -tV /bin/ls /bin/ls: (__TEXT,__text) section 00000001000010f8 pushq %rbp
00000001000010f9 movq %rsp, %rbp 00000001000010fc addq $0x68, %rdi 0000000100001100 addq $0x68, %rsi 0000000100001104 popq %rbp 0000000100001105 jmpq 0x10000465a 000000010000110a pushq %rbp 000000010000110b movq %rsp, %rbp 000000010000110e leaq 0x68(%rsi), %rax 0000000100001112 leaq 0x68(%rdi), %rsi 0000000100001116 movq %rax, %rdi 0000000100001119 popq %rbp 000000010000111a jmpq 0x10000465a 000000010000111f pushq %rbp 0000000100001120 movq %rsp, %rbp -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Logic Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
> otool -t /bin/ls /bin/ls: (__TEXT,__text) section 00000001000010f8 55 48
89 e5 48 83 c7 68 48 83 c6 68 5d e9 50 35 0000000100001108 00 00 55 48 89 e5 48 8d 46 68 48 8d 77 68 48 89 0000000100001118 c7 5d e9 3b 35 00 00 55 48 89 e5 48 8b 4f 60 4c 0000000100001128 8b 41 30 48 8b 56 60 b8 01 00 00 00 4c 39 42 30 0000000100001138 7f 1a 7d 07 b8 ff ff ff ff eb 11 48 8b 49 38 48 0000000100001148 39 4a 38 7f 07 b8 ff ff ff ff 7d 02 5d c3 48 83 0000000100001158 c7 68 48 83 c6 68 5d e9 f6 34 00 00 55 48 89 e5 0000000100001168 48 89 f9 48 8b 51 60 4c 8b 42 30 48 8b 7e 60 b8 0000000100001178 ff ff ff ff 4c 39 47 30 7f 1a 7d 07 b8 01 00 00 0000000100001188 00 eb 11 48 8b 52 38 48 39 57 38 7f 07 b8 01 00 0000000100001198 00 00 7d 02 5d c3 48 83 c6 68 48 83 c1 68 48 89 00000001000011a8 f7 48 89 ce 5d e9 a8 34 00 00 55 48 89 e5 48 8b 00000001000011b8 4f 60 4c 8b 41 20 48 8b 56 60 b8 01 00 00 00 4c 00000001000011c8 39 42 20 7f 1a 7d 07 b8 ff ff ff ff eb 11 48 8b -
> otool -tV /bin/ls /bin/ls: (__TEXT,__text) section 00000001000010f8 pushq %rbp
00000001000010f9 movq %rsp, %rbp 00000001000010fc addq $0x68, %rdi 0000000100001100 addq $0x68, %rsi 0000000100001104 popq %rbp 0000000100001105 jmpq 0x10000465a 000000010000110a pushq %rbp 000000010000110b movq %rsp, %rbp 000000010000110e leaq 0x68(%rsi), %rax 0000000100001112 leaq 0x68(%rdi), %rsi 0000000100001116 movq %rax, %rdi 0000000100001119 popq %rbp 000000010000111a jmpq 0x10000465a 000000010000111f pushq %rbp 0000000100001120 movq %rsp, %rbp -
• Tapping instructions into memory from switches • Writing bytecode
to tape or disk, and loading it • Writing machine code, and assembling it • Programming in higher-level languages -
(0) INPUT INVENTORY FILE-A PRICE FILE-B ; OUTPUT PRICED-INV FILE-C
UNPRICED-INV FILE-D ; HSP D . (1) COMPARE PRODUCT-NO (A) WITH PRODUCT-NO (B) ; IF GREATER GO TO OPERATION 10 ; IF EQUAL GO TO OPERATION 5 ; OTHERWISE GO TO OPERATION 2 . (2) TRANSFER A TO D . (3) WRITE-ITEM D . (4) JUMP TO OPERATION 8 . (5) TRANSFER A TO C . (6) MOVE UNIT-PRICE (B) TO UNIT-PRICE (C) . (7) WRITE-ITEM C . (8) READ-ITEM A ; IF END OF DATA GO TO OPERATION 14 . (9) JUMP TO OPERATION 1 . (10) READ ITEM B ; IF END OF DATA GO TO OPERATION 12 . (11) JUMP TO OPERATION 1 . (12) SET OPERATION 9 TO GO TO OPERATION 2 . (13) JUMP TO OPERATION 2 . (14) TEST PRODUCT-NO (B) AGAINST ZZZZZZZZZZZZ ; IF EQUAL GO TO OPERATION 16 ; OTHERWISE GO TO OPERATION 15 . (15) REWIND B . (16) CLOSE-OUT FILES C ; D . (17) STOP . (END) -
static void __init setup_command_line(char *command_line) { saved_command_line = memblock_virt_alloc(strlen(boot_command_line) +
1, 0); initcall_command_line = memblock_virt_alloc(strlen(boot_command_line) + 1, 0); static_command_line = memblock_virt_alloc(strlen(command_line) + 1, 0); strcpy (saved_command_line, boot_command_line); strcpy (static_command_line, command_line); } -
(defun ruby-electric--block-beg-keyword-at-point-p () "Test if there is a block beginning
keyword at point." (and (looking-at ruby-block-beg-symbol-re) (if (string= (match-string 1) "do") (looking-back "\\s-") (not (looking-back “\\."))) )) -
• Compilers: translate code between languages • Assemblers: translate assembly
language into bytecode • Interpreters: run code piece by piece -
Why Compile • Source might be valuable • Parsing can
be expensive • Optimizing is hard for humans -
Why Interpret • Source might not be valuable • Speed
might not be a big deal • Optimizing might be data-dependent -
How Do Computers Even Work? • What is Abstraction? •
Boolean Logic & Arithmetic • Logic Units and Registers • RAM, caches, the memory hierarchy • Machine language, what bytecode is • Assemblers, compilers, interpreters -
Some More Reading • Take a computer architecture class •
“Inside the Machine” by Jon Stokes • “Computer Organization and Design” by Patterson & Hennessy • Wikipedia • http:/ /j.mp/howdocomputers