300 likes | 309 Views
This chapter discusses the stored program concept, memory and data addressing in the Little Moron Computer. It covers the CPU components, instruction set and execution cycles. Examples of instructions and programs are provided.
E N D
Chapter 6 LMC Little Moron Computer
von Neumann Principles (revisited) • Stored program concept - Memory & Data • Memory is addressed linearly • Memory is addressed without regard to content1 John von Neumann, 1945
LMC Mailboxes Calculator 00 01 02 03 04 05 06 07 96 97 98 99 LM Counter
LMC Instructions • OPCODE • OPERAND Source OPERAND OPCODE Mailbox Address Instruction
Address vs. Contents G Addresses are consecutive G Contents may be data or instructions
The CPU - The Instruction Cycle START Fetch Next Instruction & Decode Fetch Cycle Execute Instruction Execute Cycle HALT
LMC Instruction Set • 1 xx ADD Arithmetic • 2 xx SUB • 3 xx STO Data Movement • 5 xx LDA • 6 xx BR Program Control • 7 xx BRZ • 8 xx BRP • 9 01 IN Input/Output • 9 02 OUT • 0 00 HLT • DAT Data Storage Location
LDA INSTRUCTION5 xx • Go to mailbox with address xx • Read 3-digit number on paper in mailbox (leave paper there) • Enter 3-digit number into calculator • Advance location counter NOTE: Accumulator changes in value. Contents of memory location xx does not change.
STO INSTRUCTION3 xx • Retrieve value from calculator • Go to mailbox at address xx and replace 3-digit number on paper in mailbox with value from calculator • Advance location counter NOTE: Accumulator does not change in value. Contents of memory location xx does change.
ADD INSTRUCTION1 xx • Go to mailbox with address xx • Read 3-digit number on paper in mailbox (leave paper there) • Add 3-digit number to number stored in calculator • Advance location counter NOTE: Accumulator changes in value.
SUB INSTRUCTION2 xx • Go to mailbox with address xx • Read 3-digit number on paper in mailbox (leave paper there) • Subtract 3-digit number from number stored in calculator • Advance location counter NOTE: Accumulator changes in value.
IN INSTRUCTION9 01 • Wait for paper slip to be placed in IN Basket. • Remove paper from IN Basket, and read 3-digit number on it • Enter number into calculator • Advance location counter NOTE: Accumulator changes in value.
OUT INSTRUCTION9 02 • Copy number from calculator onto paper • Place paper into OUT Basket • Advance location counter NOTE: Accumulator does not change in value.
BRANCH INSTRUCTION6 xx • Set value of location counter to xx
BRZ INSTRUCTION7 xx • Observe value stored in calculator • If value is 0, set value of location counter to xx
BRP INSTRUCTION8 xx • Observe value stored in calculator • If value is not negative, set value of location counter to xx NOTE: 0 value is considered positive.
HLT INSTRUCTION0 00 • LMC takes a break. NOTE: Make no assumptions about contents of memory or calculator.
ADD TWO INPUT NUMBERS • 00 IN 9 01 • 01 STO 99 3 99 • 02 IN 9 01 • 03 ADD 99 1 99 • 04 OUT 9 02 • 05 HLT 0 00 • 99 DAT 00 0 00
FIND POSITIVE DIFFERENCE OF TWO INPUT NUMBERS • 00 IN 9 01 • 01 STO 10 3 10 • 02 IN 9 01 • 03 STO 11 3 11 • 04 SUB 10 2 10 • 05 BRP 08 8 08 • 06 LDA 10 5 10 • 07 SUB 11 2 11 • 08 OUT 9 02 • 09 HLT 0 00 • 10 DAT 00 0 00 • 11 DAT 00 0 00
Problem 6.6: Find largest of 3 numbers Part 1: Find larger of two numbers and store its value in memory cell. • 00 IN 9 01 ;input three numbers and save • 01 STO 99 3 99 • 02 IN 9 01 • 03 STO 98 3 98 • 04 IN 9 01 • 05 STO 97 3 97 • 06 SUB 98 2 98 ;subtract number in 98 from that in 97 • 07 BRP 10 8 11 ;number in 97 larger • 08 LDA 98 5 98 ;number in 98 larger-restore 98 • 09 BR 11 6 11 • 10 LDA 97 5 97 ;restore 97 • 11 STO 96 3 96 ;store larger of (97, 98) in 96
Problem 6.6 (continued) • 12 SUB 99 2 99 ;subtract number in 99 from larger • 13 BRP 16 8 16 ;number in 96 larger • 14 LDA 99 5 99 ;number in 99 larger--restore 99 • 15 BR 17 6 17 • 16 LDA 96 5 96 ;restore 96 • 17 OUT 9 02 • 18 HLT 0 00 • 96 DAT 00 0 00 • 97 DAT 00 0 00 • 98 DAT 00 0 00 • 99 DAT 00 0 00
Problem 6.7 - Find Largest of N Numbers • 00 IN 9 01 • 01 STO 99 3 99 ;store the first number in 99 • 02 IN 9 01 • 03 BRZ 11 7 11 ;completion flag • 04 STO 98 3 98 ;store new value temporarily • 05 SUB 99 2 99 • 06 BRP 08 8 08 ;new value larger--store it in 99 • 07 BR 02 6 02 ;old value in 99 is larger--get next number • 08 LDA 98 5 98 • 09 STO 99 3 99 • 10 BR 02 6 02 • 11 LDA 99 5 99 • 12 OUT 9 02 • 13 HLT 0 00 • 98 DAT 00 0 00 • 99 DAT 00 0 00;contains largest number currently input
Problem 6.14: Program Loader • 00 BR 86 6 86;Jump to location 86 • … • 86 LDA 98 5 98 ;initialize the STORE instruction at location 92 • 87 STO 92 3 92 • 88 INP 9 02 ;input a value • 89 SUB 97 2 97 ;subtract 999 • 90 BRZ 01 7 01 ;done loading--jump to 01 for execution • 91 ADD 97 1 97 ;restore input value • 92 DAT 00 0 00 ;store value. This will contain 3XX, with XX indexed • ;each time • 93 LDA 92 5 92 ;load the STORE instruction in 92 • 94 ADD 99 1 99 ;increment it • 95 STO 92 3 92 ;and resave it • 96 BR 88 6 88 ;continue with the next input [NOTE: No test for exceeding ;memory] • 97 DAT 999 9 99 ;value 999 for testing • 98 DAT 301 3 01 ;initial STORE 01 instruction as a data value • 99 DAT 01 0 01 ;value 1 for indexing