The Little man computer

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

The “Little Man Computer” Version
Computer Organization and Architecture
Learning how to use the Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Assembly Language Programming CS208. Assembly Language Assembly language allows us to use convenient abbreviations (called mnemonics) for machine language.
LMC Little Moron Computer
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
The Little Man Computer
Von Neumann architecture
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Branching on Zero A Worked Example. Branching on Zero Countdown from 99 to 1, then stop Cell Code Description 00LDA Load from … 0110 … cell 10 02OUT Output.
A-Level Computing#BristolMet Session Objectives#4 MUST describe the differences between the main types of primary memory SHOULD describe the function and.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
A-Level Computing#BristolMet Session Objectives#5 MUST identify different buses and registers used in a CPU SHOULD describe the use of buses to send information.
An Interactive Web-Based Simulation of a General Computer Architecture
Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data.
LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What.
Machine Instruction Characteristics
What have mr aldred’s dirty clothes got to do with the cpu
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
CHAPTER 6: The Little Man Computer
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
Execution of an instruction
Little Man Computer When your program gets “translated to machine code” all 0’s & 1’s The translator must know the language of the program (java) as well.
DH2T 34 – HNC Computer Architecture 1 Lecture 14 The Fetch-Decode-Execute Cycle [1]. © C Nyssen/Aberdeen College 2003 All images © C Nyssen/Aberdeen College.
D75P 34 – HNC Computer Architecture
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
The Little-Man Computer Damian Gordon. The Little-Man Computer Most computer architectures conform to the so-called von Neuman Architecture. This means.
Dale & Lewis Chapter 5 Computing components
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
Examples with 3-Digit Numbers
Binary! Objectives Recap what a instruction is Look at how binary can be used to store – Opcode – data.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
This is where you can reset and run your program. If your program has an “INP” (input) command, you will type it in this box here. Using the LMC These.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Mastering LMC Coding Part #1 Introduction to Low Level Languages Introduction to Little Man computer Simple examples (demos) with video tutorials included.
Program to multiply 2 numbers 500-Input x 291-Store acc. as x 500-Input y 292-Store acc. as y 193-Load y in to acc. (0 on 1 st parse) 391-Add x to acc.
The Postman in your PC Today you are going to learn how a computer’s CPU works to handle data. Teachcompsci.co.uk.
Little Man Computer Task 1 Last lesson you were asked to write a program to multiply two numbers together. The next slide has a working program to do this.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Instruction Memory value Description ADD1xx Add the value stored at memory address xx to the value in the accumulator register SUB2xx Subtract the value.
1. 2 TimeActivity 9:45Welcome and introductions 10:00What is a computer? 10:15What’s inside? 10:45Activity: A simple view of how computers work 11:15Coffee/tea.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
The Little man computer
CHAPTER 6: The Little Man Computer
Assembly Language Programming of 8085
CHAPTER 6: The Little Man Computer
Lesson Objectives A note about notes: Aims
Starter Read the Feedback Click on Add new Feedback Open Realsmart
CHAPTER 6: The Little Man Computer
Making Programming Friendlier
Do it now – PAGE 10 You will find your do it now task in your workbook – look for the start button! Tuesday, 15 January 2019.
Computer Architecture
ECE 352 Digital System Fundamentals
DO IT NOW The LMC has the following instruction set:
DAT2343 LMC Simulator Usage © Alan T. Pinck / Algonquin College; 2003.
Little Man Computer There’s a little man in the mailroom that follows each instruction to the letter but he can only follow one instruction at a time.
Little Man Computer (continued).
A Level Computer Science Topic 5: Computer Architecture and Assembly
Learning how to use the Little man computer
Little Man Computer.
Presentation transcript:

The Little man computer

What is the Little Man Computer? Most modern computers have a processor which executes instructions and memory which stores both the instructions and any data the processor needs to use. The computer has ways of getting data from the user and ways of giving the results of any processing to the user as outputs. Modern computers are very complex machines but we can work with a simple version of a computer. This will teach us a great deal about how the computer actually works, while keeping the details quite simple to deal with. The Little Man Computer is a simulation of a modern computer system.

Which LMC? There are many implementations of the Little Man Computer (LMC). We will use the excellent web based one that can be found here: http://peterhigginson.co.uk/LM C/

Parts of the LMC Assembly instructions RAM with 100 memory locations Output CPU with 4 registers Input

Parts of the CPU CPU register Function Accumulator This stores data that is being used in calculations. It can perform simple addition and subtraction. Program Counter This contains the memory address of the next instruction to be loaded. This automatically ticks to the next memory address when an instruction is loaded. It can be altered during the running of the program depending on the state of the accumulator. Instruction Register An Instruction Register to hold the top digit of the instruction read from memory. Address register An Address Register to hold the bottom two digits of the instruction read from memory. Input This registers allows the user to input numerical data to the LMC. Output This shows the data to output to the user.

How the LMC works Modern computers work by fetching an instruction from the memory. It then decodes the instruction so that it knows what to do. It then executes the instruction, carrying out the commands, before starting all over again. This is called the Fetch-Decode-Execute cycle. The LMC understands a set of instructions and know what to do when these instructions are decoded. The LMC only understands a very limited set of instructions to show how a real processor works without becoming too complex. The list of instructions we can use is known as an instruction set.

How the LMC works The LMC will start to load the instruction from the memory address in the program counter. When the LMC first loads up this will set at zero. This memory location needs to be an instruction and will be dealt with as such. When the data is loaded the program counter is incremented to the next memory location.

LMC Instruction set The LMC processor understands 10 basic commands (plus 1 instruction to label data). The LMC only understands these instructions in a numerical form. This can be difficult for us to program in so there is a set of mnemonics we can use instead. This is known as assembly language. This will be converted into the LMC code before the program can run.

LMC Instruction set ADD 1xx Mnemonic code Instruction Numeric code Description ADD 1xx Note: the contents of the mailbox are not changed, and the actions of the accumulator (calculator) are not defined for add instructions that cause sums larger than 3 digits. SUB SUBTRACT 2xx Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results - however, a negative flag will be set so that 8xx (BRP) can be used properly. STA STORE 3xx Note: the contents of the accumulator (calculator) are not changed (non-destructive), but contents of mailbox are replaced regardless of what was in there (destructive) LDA LOAD 5xx Load the value from mailbox xx (non-destructive) and enter it in the accumulator (destructive). INP INPUT 901 Note: this will overwrite whatever value was in the accumulator (destructive) OUT OUTPUT 902 Note: the contents of the accumulator are not changed (non-destructive).

LMC Instruction set Mnemonic code Instruction Numeric code Description BRA BRANCH (unconditional) 6xx Set the program counter to the given address (value xx). That is, value xx will be the next instruction executed. BRZ BRANCH IF ZERO (conditional) 7xx Note: since the program is stored in memory, data and program instructions all have the same address/location format. BRP BRANCH IF POSITIVE (conditional) 8xx If the accumulator (calculator) is 0 or positive, set the program counter to the value xx. Otherwise, do nothing. HLT HALT Stop working. DAT DATA This is an assembler instruction which simply loads the value into the next available mailbox. DAT can also be used in conjunction with labels to declare variables. For example, DAT 984 will store the value 984 into a mailbox at the address of the DAT instruction.

Examples - input & output This program simply asks the user for an input and then outputs what was input. The program has been assembled into RAM and you can see the numeric codes for the instructions in the first three memory locations.

Using memory This program asks the user to input a number. INP STA FIRST STA SECOND LDA FIRST OUT LDA SECOND HLT FIRST DAT SECOND DAT This program asks the user to input a number. This is stored in a memory location defined by the DAT label. A second number is asked for and stored. These numbers are then loaded and output in order.

Bigger INP STA FIRST STA SECOND SUB FIRST BRP FIRSTBIG LDA SECOND OUT HLT FIRSTBIG BRZ SAME LDA FIRST SAME LDA ZERO FIRST DAT SECOND DAT ZERO DAT 0 This program uses two branch commands to alter the path of the program. There is no greater than or less than command so we simply subtract the second number from the first. If it is positive then the first number must have been bigger so we branch if positive. The two numbers could be the same however so we need to check to see if the result is zero. We branch if it is. The biggest number is output or zero if they are both the same.

Points to note The instruction set is very limited so you often need to come up with a different way to perform things like multiplication or comparing two numbers. The LMC does not store decimals. The LMC does not have a loop structure but you can use a Branch Always command to redirect the code to an earlier command.

How to Write a Little man Computer program Writing an LMC program can be quite a challenge. As the instruction set is very limited we often need to perform what seems to us to be a very simple task in an even simpler way. Using a Flow chart to help write the program is very helpful. When the flow chart is created we can simply look at each shape on the chart and think what instructions would we need to have for that shape. These will often be no more that a couple of lines of LMC code.

How to Write a Little man Computer program In flow charts there are 4 symbols that we commonly use. Symbol Meaning LMC instuctions Start / Stop Start has no instruction but Stop is HLT. Input / output OUT is the output command. It may need to be Process This could be a DAT command where we see variables initialised (e.g. counter = 0). addition and subtraction commands fit into this. A process such as X = X + Y would need to be done in the correct order. So we would Load X, Add Y and then store the result as X. This would be LDA X, ADD Y, STA X Decision There are only two instructions that can have two alternatives. Branch if Positive and Branch if Zero. If the test is true then the program can branch to another part of the program. If not the program carries on.

Example - The Problem We want a program to calculate averages. We want to be able to keep entering values until we enter a zero. The average is then calculated and displayed.

First thing - create a flow chart to show what needs to be done. Be as detailed as you can be.

Note any values you need to remember. These will be the variables. In LMC code they will become the DAT commands. Note if they have a start value.

We have 4 variables total DAT 0 count DAT 0 result DAT 0 num DAT

If we need to add on or subtract a specific value we need to be able to store that too. We need to be able to add 1 do we can do this by having one DAT 1

Assigning values can be ignored so the first command in Input number Now start at the top and write down the commands for the instructions for the flow chart. Assigning values can be ignored so the first command in Input number The LMC command is INP If we need to store that we need to follow this with a store command and save it to memory using the DAT label we created. INP STA num

Next we see if the user has entered a zero. We can use Branch Zero to do this. If the accumulator is zero we will jump to another section of the code. We need to give this section a label. I will call this section CALCULATE. I will need to do that code later. INP STA num BRZ CALCULATE

INP STA num BRZ CALCULATE LDA total ADD num STA total The next section of code happens if num does NOT equal zero. Now I need to add the num to the total. I will load the total and then add the num. LDA total ADD num This then needs to be saved back as the total. STA total INP STA num BRZ CALCULATE LDA total ADD num STA total

Now I need to add one to the count. INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count Now I need to add one to the count. So i need to load count and then add one. The result needs to be saved as count

LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP The code now loops back to the Input command. We can use a Branch always command to do this. We need to label where we want the BRA command to jump to. I will call it LOOPTOP. I need to add this label to the INP command and use it in the BRA command.

Now we need to go back to out CALCULATE code. LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP Now we need to go back to out CALCULATE code. This code performs a division. LMC does not have a divide command.

The result will store this count. LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP We can perform a divide by repeatedly subtracting the count from the total until we get to zero. Keeping a count of how many times we successfully subtract the count will be the same as dividing. The result will store this count.

This code will run in a loop. LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP This code will run in a loop. We need to load total and then subtract the count. We then need to see if the count is below zero. If it is not we will add one to the result and then loop around.

BRA LOOPTOP CALCULATE LDA total LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP CALCULATE LDA total SUB count BRP DIVIDE So the first command is to load the total and subtract the count. LDA Total SUB count Then we Branch if the result is zero or higher, so we need BRP in order to add one to the result. I will give it the label DIVIDE and deal with that later.

BRA LOOPTOP CALCULATE LDA total LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP CALCULATE LDA total SUB count BRP DIVIDE LDA RESULT OUT HLT If the value in the accumulator is negative then the BRP does not run. We now need to load the result and output it to the user. Once we do that the program is done.

BRA LOOPTOP CALCULATE LDA total LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP CALCULATE LDA total SUB count BRP DIVIDE LDA RESULT OUT HLT DIVIDE LDA result STA result BRA CALCULATE Now we need to go back to what happens if the total - count is positive. Remember we jumped to a label called DIVIDE. We need to add one to the result and then start the loop again. We can use Branch always to jump back to the top of our loop. The loop already has a label, so we can use that.

All that remains is to add the DAT commands to the end of our program. LOOPTOP INP STA num BRZ CALCULATE LDA total ADD num STA total LDA count ADD one STA count BRA LOOPTOP CALCULATE LDA total SUB count BRP DIVIDE LDA RESULT OUT HLT DIVIDE LDA result STA result BRA CALCULATE total DAT 0 count DAT 0 num DAT result DAT 0 one DAT 1 All that remains is to add the DAT commands to the end of our program.