Examples with 3-Digit Numbers

Slides:



Advertisements
Similar presentations
CHAPTER 6: The Little Man Computer
Advertisements

The “Little Man Computer” Version
Computer Architecture and the Fetch-Execute Cycle
Cpe 252: Computer Organization1 Lo’ai Tawalbeh Programming The Basic Computer Chapter 6:
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
UNIT 2. Introduction to Computer Programming
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
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
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
LMC Little Moron Computer
Program Design and Development
The Little Man Computer
Von Neumann architecture
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
+ CS 325: CS Hardware and Software Organization and Architecture Exam 1: Study Guide.
An Interactive Web-Based Simulation of a General Computer Architecture
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Machine Instruction Characteristics
Computer Systems Organization CS 1428 Foundations of Computer Science.
Chapter 4 MARIE: An Introduction to a Simple Computer.
CHAPTER 6: The Little Man Computer
Von Neumann Machine Objectives: Explain Von Neumann architecture:  Memory –Organization –Decoding memory addresses, MAR & MDR  ALU and Control Unit –Executing.
Chapter 8: The Very Simple Computer
A Simple Computer Architecture Digital Logic Design Instructor: Kasım Sinan YILDIRIM.
Execution of an instruction
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
How Computers Work in Simple english Dr. John P. Abraham Professor UTPA.
Computer Organization CSC 405 (VSC) Very Simple Computer.
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.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
Computer Architecture 2 nd year (computer and Information Sc.)
CHAPTER 6: The Little Man Computer
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
1.4 Representation of data in computer systems Instructions.
The Little-Man Computer Damian Gordon. The Little-Man Computer Most computer architectures conform to the so-called von Neuman Architecture. This means.
Electronic Analog Computer Dr. Amin Danial Asham by.
Dale & Lewis Chapter 5 Computing components
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
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.
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,
1 What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)
The Little man computer
CHAPTER 6: The Little Man Computer
Control Unit Lecture 6.
CHAPTER 6: The Little Man Computer
Review of computer processing and the basic of Operating system
Lesson Objectives A note about notes: Aims
The Selection Structure
Starter Read the Feedback Click on Add new Feedback Open Realsmart
CHAPTER 6: The Little Man Computer
MARIE: An Introduction to a Simple Computer
Computer Architecture
Computer Architecture
MARIE: An Introduction to a Simple Computer
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.
Chapter 10 Instruction Sets: Characteristics and Functions
Little Man Computer.
Presentation transcript:

Examples with 3-Digit Numbers 10’s complement representation of 247 247 (positive number) 10’s complement of 247 1000 – 247 = 753 (negative number) Example 2: 10’s complement of 17 1000 – 017 = 983 Example 3: 10’s complement of 777 Negative number because first digit is 7 1000 – 777 = 223 Sign-magnitude value = -223

Introduction Basic operations are defined by the hardware CPU instructions (operations) Data flow I/O Store program: in the memory (von Neumann) Power: not from complexity, but speed LMC: MIT 1965; 1979 (Madnick)

Goals layout of LMC functionality of LMC LMC instruction set LMC instruction codes a simple program fetch-execute instruction cycle von Neumann architecture

The Little Man Computer

LMC Architecture Memory Calculator: Location counter LM 100 mailboxes: (address, content) Addresses: 00-99 Content: 999 Calculator: S999; S = + or – No overflow Can remember the sign Location counter LM I/O: 2 baskets “01”, “02”

Instruction Code Format Instruction mailbox address 5 25 Instruction 5 == LOAD Code 525 == LOAD value from mailbox 25 onto calculator

Instruction Cycle Fetch: Little Man finds out what instruction he is to execute Execute: Little Man performs the work

Fetch Portion of Fetch and Execute Cycle 1. Little Man reads the address from the location counter 2. He walks over to the mailbox that corresponds to the location counter

Fetch, cont. 3. And reads the number on the slip of paper (he puts the slip back in case he needs to read it again later)

Execute Portion 1. The Little Man goes to the mailbox address specified in the instruction he just fetched 2. He reads the number in that mailbox (he remembers to replace it in case he needs it later)

Execute, cont. 3. He walks over to the calculator and punches the number in 4. He walks over to the location counter and clicks it, which gets him ready to fetch the next instruction

von Neumann Architecture (1945) Stored program concept Memory is addressed linearly Memory is addressed by location number without regard to content Copyright 2013 John Wiley & Sons, Inc.

LMC (Basic) Instructions Notations: Memory = M, calculator=C LOAD (5)99 from M to C STORE (3)99 from C to M STORE (4) XX Store XX to C ADD (1)99 M to C SUBTRACT (2)99 M from C INPUT (9)01 from “01” to C OUTPUT (9)02 from C to “02” HALT (0)

A Simple Program Mailbox Code Meaning 00 901 Reads from In basket to C 01 399 Store C to 99 (op1) 02 901 Reads from In basket to C 03 199 Add 99 (op1) to C 04 902 Output C to output basket 05 000 Halt The logic is: sequential The program Adds two numbers and Outputs the result

Add 3 numbers and Output Result Mailbox Code Meaning 00 901 Reads from In basket to C 01 399 Store C to 99 (op1) 02 901 Reads from In basket to C 03 398 Store C to 98 (op2) 04 901 Reads from In basket to C 05 199 Add 99 (op1) to C 06 198 Add 98 (op2) to C 07 902 Output C to output basket 08 000 Halt

Extended instructions BRANCH (JUMP) (6)99 BRANCH ON ZERO (7)99 BRANCH ON POSITIVE (8)99 Used to define new types of logic Branches Repetitions ([while; for] loops)

Primary Programming Constructs Algorithms Control structures Sequence Branching Flowcharts Pseudo-code

English vs. Code add two numbers (comments from before) input first number, input second number, add them together, output the result 901, 399, 901, 199, 902, 000

Program / Algorithm Development develop concept (in English) sketch control flow of concept fill in details convert into programming language

Three Control Structures Sequence Branching Looping

Sequence standard operation of a computer instructions are executed sequentially (from consecutively numbered memory locations) program counter increments consecutively through memory slots

Example of Sequence How do we get from here to Union Station (using the TTC)? Directions to get to Union Station are followed in sequence Get The bus Get The subway Leave at Union Station Directions are an everyday program/algorithm

Flowchart for Sequence start end

Branching allows program execution to depend on input example: “I Want to wait as little as possible for the Bus” program: Is 196 Line too long ? Go get the 106.

Flowchart for Branching 196 Line long? Get 106 yes no

Pseudocode Pseudocode is a brief English description of an algorithm (the comments from before) it is not natural English it does not have complete detail it is not syntactically correct code

Grading Example 85-100 Honors 60-84 Pass Fail start input grade yes no end

Summary Programming == algorithm development + coding algorithm development requires clarity of thought coding requires attention to detail

Looping Examples of looping Structured programming Writing pseudocode

Looping allows program to repeatedly execute a given section example: deal all the cards from the deck program: check to see if there are more cards deal a card < repeat >

Flowchart for Looping more cards? deal a card yes no

Example of Looping Mailbox Code Meaning <assume that calculator value represents number of remaining cards > 19 299 Subtract 99 from C (consider 99 holding the value 1) 20 822 if positive, branch to 22 21 630 branch to 30 (skip code to deal card) 22… < code to deal cards > 29 619 branch to 19 (repeat until no more cards) 30 < remainder of program > 99 001

Structured Programming Any program can be written with only the three primary constructs Branch unconditionally (goto) is not externally available

Natural Language to Pseudocode Use a large sauce pan Bring 4 litres of water to a rolling boil Add salt to taste, if desired Add contents of package Stir gently Boil 11 minutes Remove from heat Drain well Serve

For A payroll System : Input the employees payroll data If hours worked is greater than 40 then calculate overtime pay Calculate gross pay for the employee - Gross Pay = hourly pay times 40 plus overtime Calculate tax for the employee

Summary Natural language is NOT pseudocode Programming requires great explicitness of thought Details are easier to fill in after you have the algorithm figured out

Program 2 00 IN “01” 901 Input from “01” to C [op1] 01 STO 10 310 Store from C to M10 02 IN “01” 901 Input from “01” to C [op2] 03 STO 11 311 Store from C to M11 04 SUB 10 210 Subtract op2-op1 = r1 05 BRP 08 808 If r1 > 0 goto M08 06 LDA 10 510 else load op1 into C 07 SUB 11 211 op1-op2 = r2 08 OUT “02” 902 Output to “02” 09 HLT 10 Data 11 Data

Program 2 00 IN “01” 901 Input from “01” to C [op1] 01 STO 10 310 Store from C to M10 02 IN “01” 901 Input from “01” to C [op2] 03 STO 11 311 Store from C to M11 04 SUB 10 210 Subtract op2-op1 = r1 05 BRP 08 808 If r1 > 0 goto M08 06 LDA 10 510 else load op1 into C 07 SUB 11 211 op1-op2 = r2 08 OUT “02” 902 Output to “02” 09 HLT 10 Data 11 Data

How to do C-(A+B) ? 00 Input 901 01 Store 20 320 02 Input 901 03 ADD 20 120 04 Store 21 321 05 Input 901 06 SUB 21 221 07 Output 902 08 Halt 0 Read A Read B Sum D=A+B Read C Sub C-D

Compare A and B. Output Letter C if A greater and D otherwise 00 Input 901 01 Store 20 320 02 Input 901 03 Sub 20 220 (B-A) 04 BRP 08 808 05 STVAL 67 467 (43 hex) 06 Output 902 07 Halt 000 08 STVAL 68 468 (44 hex) 09 Output 902 10 Halt 0 Read A Read B IF A>B Then Write “C” Else Write “D”

Other Alternative 00 Input 901 01 Store 20 320 02 Input 901 03 Sub 20 220 (B-A) 04 BRP 07 807 05 STVAL 67 467 06 Branch 08 608 07 STVAL 68 468 08 Output 902 09 Halt 0

Subtract 10-8 and Add to A (input) Subtract 10-8 and Add to A (input). If result >10 Output 1 else Output 2 A=10 B=8 C=A-B Read D E=D-C IF E>10 write “1” Else write “2”

Subtract 10-8 and Add to A (input) Subtract 10-8 and Add to A (input). If result >10 Output 1 else Output 2 00 Stval 08 408 01 Store 21 321 02 Stval 10 410 03 Sub 21 221 04 Store 21 321 05 Input 901 06 Add 21 121 07 Store 21 221 08 StVal 10 410 Sub 21 221 (10 – Result) 10 BRP 13 813 11 Staval 50 450 12 Branch 14 614 13 Stval 49 449 14 Output 902 15 Halt 0

Multiply A*B Read A Read B C=0 While A>0 Do C=C+B A=A-1 Enddo Write B

00 Input 901 01 Store 21 321 02 Input 902 03 Store 22 322 04 Stval 0 400 05 Store 23 323 06 Staval 1 411 07 Store 24 324 08 Load 23 523 09 Add 22 122 10 Store 23 323 11 Load 21 521 12 Sub 24 224 BZ 16 716 Store 21 321 15 Branch 08 608 16 Load 23 523 17 Output 902 18 Halt 0

Is the LMC a “real” computer? CPU instruction set is created using binary numbers rather than decimal Instructions are performed in a simple electronic way using logic based upon Boolean algebra instead of having a Little Man running around a mailroom.

LMC to “real” computer LMC also uses fetch-execute cycles LMC processes instructions in sequence Mailboxes are memory LM and calculator are CPU Baskets provide I/O

Summary LMC is almost real computer! Computers are simple Programming is easy