Professional Documents
Culture Documents
How Computers Work: Subject Purpose
How Computers Work: Subject Purpose
Subject Purpose
fact-iter:
(test (op =) (reg n) (const 0))
(branch (label done))
(assign (reg val) (op *) (reg n) (reg val))
(assign (reg n) (op -) (reg n) (const 1))
(goto (label fact-iter))
Attempt #1:
Program Data
Memory Memory
.
. 2
5
.
ADD 43264 932643 43265
<pc>-->
.
. 3
SALE
Fast
Cheap (Large)
How Computers Work Lecture 1 Page 11
Actual Memory Systems
ST R2, 43265
e.g. ADD R0 R1 R2
32 bits
next instr
r31 always 0
OPCODE Ra Unused Rb Rc
SUB, SUBC
OPCODE Ra Unused Rb Rc (optional)
MUL, MULC
DIV, DIVC
What we prefer to see: symbolic ASSEMBLY LANGUAGE
ADD(ra, rb, rc) rc <ra> + <rb> BITWISE LOGIC:
Add the contents of ra to the contents of AND, ANDC
rb; store the result in rc OR, ORC
XOR, XORC
x=0x1002 ; variable x
or, more y=0x1003 ; variable y
humanely,
to LD(x, r0) ; r0 gets x
MULC(r0, 37, r0) ; r0 gets x*37
ST(r0, y) ; y gets x*37
x: 0 VARIABLES translate to LD or ST
y: 0
OPERATORS translate to ALU
c: 123456 instructions
... SMALL CONSTANTS translate to
LD(x, r1) literal-mode ALU instructions
SUBC(r1,3,r1) LARGE CONSTANTS translate to
LD(y, r2) LD Instruction (or LDR)
LD(c, r3)
ADD(r2,r3,r2)
MUL(r2,r1,r1)
ST(r1,y)
How Computers Work Lecture 1 Page 25
Our Favorite Program
n: 20
; assume n is 20, val is 1 val: 1
01101101
STREAM of Words
Assembler 11000110
00101111
10110001 to be loaded
.....
into memory
Symbolic Translator Binary
SOURCE program Machine
text file Language
Symbol
Textual Memory +
Macro Expression
Pre-Processor Evaluator
0b100101
binary (0b prefix);
0x25
hexadecimal (0x prefix);
x = 1 | 1
y = x + 1 | 2
x: 0
by the definitions