gcse computing – the lmc

13
© GCSE Computing Candidates should be able to: describe the characteristics of an assembler Slide 1

Upload: farren

Post on 30-Jan-2016

61 views

Category:

Documents


0 download

DESCRIPTION

Candidates should be able to: describe the characteristics of an assembler. GCSE Computing – the LMC. LMC stands for Little Man Computer . The LMC is a CPU simulator that models a simple computer using the von Neumann architecture and memory use - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: GCSE Computing – the LMC

© GCSE Computing

Candidates should be able to: describe the characteristics of an assembler

Slide 1

Page 2: GCSE Computing – the LMC

© GCSE Computing

LMC stands for Little Man Computer. The LMC is a CPU simulator that models a simple computer using the

von Neumann architecture and memory use a central processing unit consisting of an arithmetic logic unit and registers a control unit containing an instruction register and program counter input and output mechanisms RAM to store both data and instructions external secondary storage

The simulation uses the idea of a ‘Little Man’ inside the computer fetching instructions from RAM and executing them.

The LMC can be programmed directly by entering machine code (but in decimal) directly into RAM.

However, the LMC is usually programmed in assembly code. An assembler then translates the assembly code into machine code

(but in decimal) and loads it into RAM.

Slide 2

Page 3: GCSE Computing – the LMC

© GCSE Computing

RAM consisting of 100 memory addresses (0-99). Each address can hold a decimal format number up to 999.

INPUT using a 0-9 digit keypad. OUTPUT using a multi-line display. A PROGRAM COUNTER that stores the address

of the next instruction in RAM. An INSTRUCTION REGISTER that stores the

OPP CODE of the current instruction. An ADDRESS REGISTER that stores the address

part of the current instruction (if it has one). An ACCUMULATOR that stores the results of any

calculations.

Slide 3

Page 4: GCSE Computing – the LMC

© GCSE Computing

As the simulation runs the ‘Little Man’ inside the computer carries out the following steps:1. Check the Program Counter to find the RAM address with the

program instruction to be fetched.2. Fetch the INSTRUCTION from that RAM address.3. Increment the Program Counter (so that it contains the RAM address

of the next instruction).4. Decode the instruction (this might include finding the RAM address for

the data it will work on).5. If necessary, fetch the DATA from the RAM address found in the

previous step.6. Execute the instruction.7. Repeat the cycle or halt.

Slide 4

Page 5: GCSE Computing – the LMC

© GCSE Computing Slide 5

Memory addresses

0-99

A program in

ASSEMBLY LANGUAGE ready to be translated

into machine

code

INPUT, allowing number

data input

OUTPUT, displayin

g number

data output

An explanation of the

instruction to be executed

next

Page 6: GCSE Computing – the LMC

© GCSE Computing Slide 6

The ADDRESS REGISTER, containing

the ADDRESS that the current

instruction code refers to

The program

in ASSEMBL

Y LANGUAGE without LABELS

The contents of the

ACCUMULATOR

The PROGRA

M COUNTE

RThe

INSTRUCTION

REGISTER, containing the current INSTRUCTION CODE

Page 7: GCSE Computing – the LMC

© GCSE Computing Slide 7

DATA stored in RAM

MACHINE CODE

instructions stored in

RAM

DATA

The program

in ASSEMBL

Y LANGUA

GE

Page 8: GCSE Computing – the LMC

© GCSE Computing

Labels can be used to label a memory address that contains DATA. Being able to refer to the data as a label is much easier than having to refer to the address the data is stored at.

Example: data1 DAT

Explanation: The memory address where this data is stored is labelled data1. No data would initially be stored at this location. If this was the 7th line of assembly code to be compiled then the label would refer to memory address 6 (RAM addresses start at 0)

data1 DAT 50 Explanation: The memory address where this data is stored is labelled data1 and

stores the data 50. If this was the 7th line of assembly code to be compiled then the data 50 would be stored at memory address 6 (RAM addresses start at 0)

STA data1 Explanation: The contents of the accumulator would be stored at memory address 6.

LDA data1 Explanation: The data which is stored at memory address 6 would be loaded into the

accumulator.

Slide 8

Page 9: GCSE Computing – the LMC

© GCSE Computing

Labels can be used to label a memory address that contains an INSTRUCTION. Being able to refer to the label rather than the address of the instruction makes it much easier when using BRANCH instructions such as BRA, BRP and BRZ.

Example: loop1 INP

Explanation: The memory address where this instruction is stored would be labelled loop1.

BRZ loop1 Explanation: If the contents of the accumulator were zero, the program

would branch to the memory address labelled loop1 and carry out the instruction there.

To achieve this, the Program Counter would be set to the memory address labelled loop1.

If the contents of the accumulator were not zero then the Program Counter would simply be incremented by one.

Slide 9

Page 10: GCSE Computing – the LMC

© GCSE Computing Slide 10

Labels used with BRANCH

instructionsLabels

used with DATA

Page 11: GCSE Computing – the LMC

© GCSE Computing

After a program is assembled into machine code the Program Counter is always reset to memory address 0.

1. The ‘Little Man’ checks the Program Counter to find the RAM address with the instruction to be fetched (in this case address 0).

2. Here, the instruction 523 is fetched from RAM address 0.

3. The Program Counter is incremented (to RAM address 1).

4. The instruction part (5) is loaded into the INSTRUCTION REGISTER and the address part (23, the RAM address for the data the instruction will work on) is loaded into the ADDRESS REGISTER.

5. The instruction is then decoded.

6. The instruction is executed (5 = LOAD into ACCUMULATOR so the 0 stored at RAM address 23 is loaded into the ACCUMULATOR).

7. Back to step 1 to repeat the cycle until a HALT instruction is reached.

Slide 11

Page 12: GCSE Computing – the LMC

© GCSE Computing

An instruction starting with a 9 (901 or 902) means the instruction is an INPUT/OUTPUT command.

The ‘address’ part of the instruction (01 or 02) decides if the instruction is actually an INPUT or an OUTPUT. 01 means INPUT - entered using the number keypad and stored

in the ACCUMULATOR when the Enter key is pressed. 02 means OUTPUT – the value stored in the ACCUMULATOR is

passed to the OUTPUT box.

Slide 12

Page 13: GCSE Computing – the LMC

© GCSE Computing

Instruction Mnemonic

Machine Code

Load LDA 5xx

Store STA 3xx

Add ADD 1xx

Subtract SUB 2xx

Input INP 901

Output OUT 902

End HLT 000

Branch always BRA 6xx

Branch if zero BRZ 7xx

Branch if zero or positive

BRP 8xx

Data storage DAT

Slide 13

NOTE: xx represents a memory address between 0 and 99.