Hello World! An Invitation to Computer Science

Lecture Slides

Computer Architecture and
Machine Code
Thursday, March 6, 2008


Key ideas from last time


Registers


Arithmetic Logic Unit (ALU)


Control


Machine language


Architectural varieties


Instruction categories


Machine instructions v. pseudocode

if we can do all three, we can
  execute any algorithm at machine level


Example: 2 + 4 = 6

 addr       data          hex   op     meaning
 ---------------------------------------------
 000   0000000000000101   0005  LOAD   R ← CON(5)
 001   0011000000000110   3006  ADD    R ← R + CON(6)
 010   0001000000000111   1007  STORE  CON(7) ← R
 011   1110000000000111   E007  OUT    display CON(7)
 100   1111000000000000   F000  HALT   
 101   0000000000000010   0002
 110   0000000000000100   0004
 111   0000000000000000   0000

Example: 1 + 2 + ... + n

  0  LOAD i
  1  COMPARE n
  2  JUMPLT ...
  3  LOAD sum
  4  ADD i
  5  STORE sum
  6  INCREMENT i
  7  JUMP 0
  8  OUT sum
  9  HALT