Primary Programming Constructs - PowerPoint PPT Presentation

About This Presentation
Title:

Primary Programming Constructs

Description:

Used for high-speed temporary storage. ITEC 1011. Introduction to Information ... The usage of memory space on a system is commonly depicted in a 'memory map' ... – PowerPoint PPT presentation

Number of Views:126
Avg rating:3.0/5.0
Slides: 39
Provided by: jimmy50
Category:

less

Transcript and Presenter's Notes

Title: Primary Programming Constructs


1
Primary Programming Constructs
  • Algorithms - a finite sequence of steps for
    solving a logical or mathematical problem or
    performing a task
  • Control structures - set of statements, controls
    the execution
  • Sequence one statement simply follows another
  • Branching program flow depends on which criteria
    are met
  • Iteration action is repeated until some
    condition occurs
  • Flowcharts a graphic map of an algorithms.
  • Pseudo-code brief English description of an
    algorithm

2
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

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

4
Three Control Structures
  • Sequence
  • Branching
  • Looping

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

6
Example of Sequence
  • How do we get from here to SkyDome (using the
    TTC)?
  • Directions to get to SkyDome are followed in
    sequence

7
Flowchart for Sequence
start
end
8
Branching
  • allows program execution to depend on input
  • example
  • if you pass this course, you will get three
    credits
  • program
  • check to see if you passed
  • grant three credits

9
Flowchart for Branching
passed?
grant 3 credits
yes
no
10
New Instructions
  • BRANCH 6 mailbox address
  • BRANCH ON ZERO 7 mailbox address
  • BRANCH ON POSITIVE 8 mailbox address

11
Example of Branching
  • Assume calculator has value of (YourGrade
    PassingGrade)
  • Mailbox Code Meaning
  • 20 822 if positive, branch to 22
  • 21 630 branch to 30 (skip code to grant
    credits)
  • 22 lt code to grant credits gt
  • .
    .
  • .
    .
  • .
    .
  • 30 lt remainder of program gt

12
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

13
Grading Example
start
input grade
yes
Honors 85-100 Pass 60-84 Fail 0-59
Honors
85-100
no
yes
Pass
60-84
no
Fail
end
14
Grading Example 2
  • input grade
  • if ( )
  • __________________
  • else if ( )
  • _______________
  • else
  • ____________

15
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
  • lt repeat gt

16
Flowchart for Looping
morecards?
deal a card
yes
no
17
Example of Looping
  • Mailbox Code Meaning
  • ltassume that calculator value represents number
    of remaining cards gt
  • 20 822 if positive, branch to 22
  • 21 630 branch to 30 (skip code to deal card)
  • 22 lt code to deal cards gt
  • .
    .
  • .
    .
  • 29 620 branch to 20 (repeat until no more
    cards)
  • 30 lt remainder of program gt

18
Summary
  • Programming
  • algorithm development coding
  • algorithm development requires clarity of thought
  • coding requires attention to detail

19
The CPU and Memory
20
Introduction
In a Computer Memory is separate from the
CPU Data is in binary (not decimal)
CentralProcessingUnit
21
System Block Diagram
CPU
Highest Address Memory Lowest Address
ALU
Input/outputinterface
Control unit Program counter
22
The Little Man Computer
23
Components of a CPU
  • ALU (arithmetic and logic unit)
  • Performs arithmetic and logic operations
  • Arithmetic add, subtract, multiply, divide, etc.
  • Logic AND, OR, NOT, Shift, etc.
  • Control unit
  • Interprets instructions
  • Controls the flow of information within the CPU
  • Works with a program counter (address of next
    instruction)
  • Input/output interface
  • Provides mechanism for input and output of data
  • Many variations possible

24
Registers
  • A register is a single storage location within
    the CPU
  • Unlike memory, which is outside the CPU
  • Examples of registers
  • Accumulator (ACC)
  • Program counter (PC)
  • Instruction register (IR)
  • Memory address register (MAR)
  • Memory data register (MDR)
  • Status register
  • General purpose registers (R0, R1, )
  • Included on some CPUs
  • Used for high-speed temporary storage

25
Memory Capacity
  • 2n x m bits
  • n address bits 2n addresses
  • m data bits usually m 8 (for one byte)
  • m is the width of the data path
  • Typical values
  • n 16, 17, 18, 19, 20, 21, 22, etc.
  • m 8, 16, 32, 64

26
Question
  • Q How many bits of memory are contained in a
    memory unit with 512KB of memory?
  • A 512 29, K 210, B byte 8 23
  • 29 x 210 x 23 222 4,194,304

27
Exercise Memory Capacity
  • Q How many bits of memory are contained in a
    memory unit with 2MB of memory?
  • A

Skip answer
Answer
28
Exercise Memory Capacity
  • Q How many bits of memory are contained in a
    memory unit with 2MB of memory?
  • A 2 21, M 220, B byte 8 23
  • 21 x 220 x 23 224 16,777,216

Answer
29
Memory Unit
n bits
Memory cell
bit 0
0 1 2 3 4 2n-1
bit 1
Memory address register
Address decoder
bit n - 1
0 1 2 m - 1
Memory data register
m bits
p. 160
30
MAR-MDR example
31
A visual analogy for memory
32
An individual memory cell
33
Memory Implementations
  • RAM random access memory
  • Static RAM
  • Dynamic RAM
  • Both static and dynamic RAM are volatile
  • ROM read-only memory
  • Nonvolatile and unwritable

Page 175
p. 165
34
Memory Capacity
  • Determined by
  • Number of bits in MAR
  • Number of bits in the instruction address field
  • Types of memory
  • Physical
  • Logical/Virtual
  • Memory content manipulation 4 or 8 bytes

35
Memory Maps
  • The usage of memory space on a system is commonly
    depicted in a memory map
  • The height of the map is determined by the number
    of addresses
  • The width of the map is usually 8 bits
  • E.g.,
  • a system with a capacity of 216 bytes

36
Memory Map
7 6 5 4 3 2 1 0
FFFF 0002 0001 0000
Data bitposition
The bottom of memory
Hexadecimaladdress
37
Use of Memory Maps
  • Memory maps are usually drawn to show what is
    where on a system
  • The possibilities for what
  • RAM, ROM, I/O, nothing
  • The possibilities for where
  • Determined by the starting/ending addresses for
    each block of RAM, ROM, I/O, nothing
  • E.g.,
  • a memory map for a system with a capacity of 224
    bytes with two 1 MB RAM modules residing
    consecutively at the bottom of memory.

38
Memory Map
FFFFFF 200000 1FFFFF 100000 0FFFFF 00
0000
14 MB empty
224 bytes 16 MB capacity
1 MB RAM
1 MB RAM
Write a Comment
User Comments (0)
About PowerShow.com