Little Man Computer
Components Memory (100 cells numbered 0 to 99) Program Counter Holds machine language instructions and data Program Counter Holds the address of the next instruction to be executed Accumulator Holds the result of the most recent ADD / SUB instruction In box Where the computer gets its input Out box Where the computer sends its ouput
Instructions OpCode Mnemonic Description HLT Halt execution 1 ADD HLT Halt execution 1 ADD Add memory cell to accumulator 2 SUB Subtract memory cell from accumulator 3 STA Store accumulator to memory cell 4 LDA Load memory cell to accumulator 5 BRA Set program counter to operand 6 BRZ Set program counter to operand only if accumulator is zero 7 INP Load in box to accumulator 8 OUT Write accumulator to out box
LMC Machine Language Each machine language instruction is a 3-digit number 3 1 9 The opcode specifies which instruction to execute The operand specifies additional information needed by the instruction
3 1 9 LMC Assembly Language STA 19 An assembly language instruction is a decoded machine language instruction 3 1 9 STA 19
Execution Cycle Fetch => Decode => Execute
Example – Add 2 Numbers Get a number from input into calc Copy that number to an unused mailbox (mailbox 99) Get another number from input into calc Add the number we put into a mailbox 99 to calc Copy calc to the output Halt
Example – Add 2 Numbers Address Machine Language Assembly 700 INP 1 700 INP 1 399 STA 99 2 3 199 ADD 99 4 800 OUT 5 000 HLT
Example – Count Down to Zero Address Machine Language Assembly 700 INP 1 605 BRZ 5 2 800 OUT 3 206 SUB 6 4 501 BRA 1 5 000 HLT 6 001 DAT 1
Example – Read / Write Two Numbers But Swap Them Get a number from input into calc Copy the number to an unused mailbox (mailbox 99) Copy the number to an unused mailbox (mailbox 98) Copy the value from mailbox 98 to calc Copy the value in calc to output Copy the value from mailbox 99 to calc
Example – Read / Write Two Numbers But Swap Them INP (700) STA 99 (399) STA 98 (398) LDA 98 (598) OUT (800) LDA 99 (599)
Example – Multiply by 3 if Positive INP (700) STA 99 (399) STA 98 (398) STA 97 (397) LDA 98 (498) ADD 13 (113) BRZ 13 (613) LDA 97 (497) SUB 13 (213) BRZ 17 (617) BRA 04 (504) 1 (this is data, not an instruction) LDA 99 (399) OUT (800) HLT (000) ADD 99 (199)