Instruction Addressing and Programming Tools - PowerPoint PPT Presentation

Loading...

PPT – Instruction Addressing and Programming Tools PowerPoint presentation | free to download - id: 6b2b47-NmM1M



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Instruction Addressing and Programming Tools

Description:

ITEC 1000 Introduction to Information Technology Lecture 7: Instruction Addressing and Programming Tools {Prof. Peter Khaiter} – PowerPoint PPT presentation

Number of Views:6
Avg rating:3.0/5.0
Date added: 13 February 2020
Slides: 64
Provided by: Khaiter
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Instruction Addressing and Programming Tools


1
Lecture 7
ITEC 1000 Introduction to Information Technology
  • Instruction Addressing and Programming Tools

Prof. Peter Khaiter
2
Lecture Template
  • Direct, Absolute Addressing
  • Register Addressing
  • Base Register Addressing
  • Relative Addressing
  • Direct Addressing and Alternatives
  • Programming Tools
  • Program Translation Process
  • Assembly Language
  • Interpreter vs. Compiler

3
Direct, Absolute Addressing
  • Direct data is reached directly from the
    address in the instruction
  • Absolute address in the instruction field is
    the actual memory location being addressed

4
Additional Addressing Modes
  • Programmer-accessible registers
  • Provide faster execution with register-based
    instructions
  • Alternatives to absolute addressing
  • Allow larger range of addressable memory
  • While using a reasonable number of bits for the
    address field
  • Alternatives to direct addressing
  • Facilitate writing certain types of programs
  • Example loops that use index to address
    different entries in a table or array

5
Register Addressing
  • Does not require a memory access
  • Contents of the source register is directly moved
    to the destination register
  • Faster execution as memory is not accessed
  • Practical application frequently used data to be
    loaded from memory into registers and left there
  • Implemented directly as part of the CPU
  • All registers are located in the CPU (as a part
    of ALU or a separate register unit)

6
Register Instruction
ADDRESS 2
ADDRESS 1
7
Register Addressing
Fetch-Execute Cycle for Register-to-Register Move Fetch-Execute Cycle for Register-to-Register Move
PC -gt MAR Transfer the address from the PC to the MAR
MDR -gt IR Transfer the instruction to the IR
contents(IRadd1) -gt contents(IRadd2) Move contents of source register to destination register
PC 1 -gt PC Program Counter incremented
Done in parallel with the move only 3 time
units required
8
Active Area of Memory
  • Code executes in a small area of memory that
    changes as program proceeds
  • Well-written code
  • Small modular subroutines and procedures
  • Local variables
  • Conditional branches

9
Two Alternatives to Absolute Addressing
  • Base register addressing
  • Relative addressing
  • Both provide starting address and an offset or
    displacement from the starting point
  • Starting address in register or program counter
  • Offset address in the instruction
  • Programming advantage permits to move the entire
    program to a different location in memory without
    changing any of the instructions (i.e.,
    relocatability)

10
Base Register Addressing
  • Base register set to initial address
  • Hardware design special/separate register or
    general-purpose registers
  • Generally large to provide large memory space,
    frequently gigabytes
  • Final address contents of instruction address
    field added to the base address

11
IBM zSystem
  • Base register address creation

Base 1375 1375 1 20 Instruction
Register 1375 20

1395 actual location (absolute address in memory) actual location (absolute address in memory) actual location (absolute address in memory) actual location (absolute address in memory)
12
IBM zSystem Load Instruction
  • 16 64-bit general-purpose registers
  • Load instruction format

GP register holds the base address value
op code reg index base offset
bit 0 7 8 11 12 15 16 19 20 31
Destination GP register to get data from memory
13
IBM zSystem Example Load
  • Base-value register general-purpose register 3
  • 1 C 2 5 E 016
  • Displacement/Offset for the instruction
  • 3 7 A16
  • Absolute address

1 C 2 5 E 016
3 7 A16
1 C 2 9 5 A16
14
IBM zSystem Example Load
  • Instruction Word

Base register
58 6 0 3 37A
Displacement/Offset
15
Relative Addressing
  • Value in address field added to value in program
    counter
  • Program counter used as the base register
  • Similar to base addressing
  • Constraint address field must be able to store
    and manipulate positive and negative (to jump
    backwards in loops) numbers
  • Complementary representation

16
Relative Addressing Example
Program Counter 46 46 1 3 Instruction
Program Counter 46 3

49 actual location (absolute address in memory) actual location (absolute address in memory) actual location (absolute address in memory) actual location (absolute address in memory)
17
Fetch-Execute Cycle for Relative Address ADD
Instruction
PC -gt MAR Transfer the address from the PC to the MAR
MDR -gt IR Transfer the instruction to the IR
IRAddress PC -gt MAR Address portion of the instruction added to the PC and loaded into the MAR
MDR A -gt A Value in the MDR added to the value of the accumulator
PC 1 -gt PC Program Counter incremented
18
Direct Addressing
  • Location of data is different from location of
    instructions
  • Benefits to programmer
  • Data can be changed without affecting the
    instruction itself
  • Data is available to different instructions
  • Variable can be assigned to a particular location
    in memory independent of the instructions that
    refer to data

19
Alternatives to Direct Addressing
  • Immediate addressing
  • Indirect addressing
  • Register Indirect addressing
  • Indexed addressing

20
Immediate Addressing
  • Store data with the instruction itself
  • Example
  • Data is a constant
  • Constraint
  • Address field must be able to store and
    manipulate positive and negative numbers
  • Complementary representation
  • Instruction must include extra bits to identify
    the addressing mode
  • Change instruction if the constant has to be
    changed
  • Advantage
  • Additional memory access (to obtain the data) is
    not required
  • Faster execution

21
Immediate Addressing
  • The size of the constant is limited to the size
    of the address field (here two digits)
  • Addressing mode 1 indicates immediate addressing

op code addressing mode addressing mode addressing mode address field

1 1 05
(Load) (the number 05)
22
Fetch-Execute Cycle for Immediate Addressing
Load Instruction

PC -gt MAR Transfer the address from the PC to the MAR
MDR -gt IR Transfer the instruction to the IR
IRAddress-gt A Move contents of the address field of the instruction to Accumulator
PC 1 -gt PC Program Counter incremented
23
Indirect Addressing
  • Separates the address of the data from the
    instruction
  • Address field of the instruction contains the
    address of the address of the data (memory
    location is a pointer to address)
  • Address of data varies during execution
  • Address of data can change to reflect the current
    subscript without modifying address in the
    instruction
  • Similar to pointers in Pascal or C
  • Frequently used with subscripted data in a table

Memory address Data Table Subscript
77 136 TABLE(1)
78 554 TABLE(2)
79 302 TABLE(3)

24
Indirect Addressing
addressing mode (2indirect addressing)
address field
op code
0101
0011
0010
0001
(the number 05)
(Load)
Destination register (R3)
Memory
0111
0000
0101
0111
25
Fetch-Execute Cycle for Indirect Addressing Load
Instruction

PC -gt MAR Transfer the address of the instruction from the PC to the MAR
MDR -gt IR Transfer the instruction to the IR
IRAddress-gt MAR 4. MDR -gt MAR Move contents of the address field of the instruction to the MAR Move contents of the MDR to the MAR, as it is address, not operand
5. MDR -gt R3 Contents of the MDR loaded into R3
6. PC 1 -gt PC Program Counter incremented
26
Incrementing
  • Treat the instruction as data
  • Modify the address field
  • Pure code does not modify itself during
    execution
  • Incrementing does not modify the instruction
  • Address stored in a separate data region
  • Advantage program can be stored in ROM

27
Mailbox Instruction Instruction Comments
00 LOAD 90 /this actually loads "ADD 60"..
01 STORE 07 /..into mailbox 07
02 LOAD 91 /initialize the totalizer
03 STORE 99
04 LOAD 92 /initialize the counter to 19
05 STORE 98
06 LOAD 99 /load the total
07 0 /ADD 60, ADD 61, etc.
08 STORE 99 /and store the new total
09 LOAD 07 /modify the instruction in 07..
10 ADD 93 /..by adding 1 as though the ..
11 STORE 07 /..instruction were data
12 LOAD 98
13 SUB 93 /decrement the counter
14 STORE 98
15 BRP 06 /loop back if not done
16 LOAD 99 /done..
17 OUT /output the result
18 HALT

90 ADD 60 /initial data for location 07
91 0
92 19
93 1
98 /used to hold the current count
99 /used to hold the current total
Instruction in location 07 treated as data,
incremented, and replaced to its original location
Totalizer Loop with Direct Addressing
28
Mailbox Instruction Instruction Comments
00 LOAD 90 /this time just the initial..
01 STORE 97 /..address is saved..
02 LOAD 91 /as..
03 STORE 99
04 LOAD 92 /
05 STORE 98
06 LOAD 99 /before
07 ADD 97 /this is the indirect instruction
08 STORE 99
09 LOAD 97 /modify the address in 97 (this is direct)..
10 ADD 93 /..by adding 1 to it
11 STORE 97
12 LOAD 98 /as
13 SUB 93
14 STORE 98
15 BRP 06 /
16 LOAD 99
17 OUT /before
18 HALT

90 60 /now this is the initial address
91 0
92 19
93 1
97 /used to hold the address of the data
98 /used to hold the current count
99 /used to hold the current total
Asterisk used to indicate indirect instruction
Totalizer Loop with Indirect Addressing
29
Register Indirect Addressing
  • Also called register deferred addressing
  • Address pointer is stored in a general-purpose
    register
  • Advantage efficient
  • One instruction to load pointer address in
    register
  • Data accessed in the same number of fetch-execute
    instructions as direct addressing
  • Small address field required (3 or 4 bits)
  • Excellent for addressing large memory space with
    small instruction word

30
Register Indirect Addressing Duel Duty
  • Autoincrementing/autodecrementing
  • Direct implementation of Cs and - -
  • Instruction
  • Performs normal functions like LOAD or ADD
  • Plus increments or decrements register each time
    instruction executed
  • Advantage simplifies writing program loops
  • Replaces steps 7,9,10, 11 on Slide 28

31
Register Indirect Addressing Obtaining Data
32
Motorola 68000 CPU MOVE
6 bits (3 for register, 3 for mode)
4 bits
  • 16 GP registers 8 for data 8 for addresses
  • Single instruction does both LOAD and STORE
    (moves data register to register, register to
    memory, memory to register, memory to memory)

33
Indexed Addressing
  • Use address in the instruction like direct
    addressing
  • But modify address by adding value from another
    register
  • General purpose or special index register
  • If the value in index register is 0, index
    addressing becomes direct addressing

34
Index Register Modifying an Address
35
Indexed vs. Base Offset
  • Both offset address by amount stored in another
    register
  • Base offset primarily to expand addressing
    range for a given address field size
  • Value of base address likely to be large and
    rarely changed during execution
  • Index register primarily used as a table offset
    for subscripting
  • Value in index register most like small and
    frequently changing
  • Autoindexing similar to autoincrementing
    (except that the index register is incremented)

36
Using Both Base Offset and Indexed Addressing
37
Totalizer Loop with Indexed Addressing
Mailbox Instruction Instruction Instruction Comments
00 LDA 91 91 /total is kept in A. This sets A to 0 (not indexed).
01 LDX 92 92 /initialize the counter to 19
02 ADD _at_ 60 60 /ADD 79, ADD 78, etc. as X is decremented
03 DEC X X /Decrement the index 19, 18, etc.
04 BRPX 02 02 /test if done (when X decrements from 0 to -1)
05 OUT OUT /done output the result from A
06 HALT HALT
91 0 0
92 19 19
Note _at_ symbol indicates indexed instruction LDX LOAD register
X is the indexed register (offset and counter) LDA LOAD accumulator
38
Programming Tools
  • Editors
  • Assemblers
  • Debuggers
  • Compilers
  • Linking editors
  • Loaders
  • Interpreters

Integrated Development Environments (IDEs)
combine several of the above programming tools
39
Programming Tools
  • Editors entering and modifying program in text
    form
  • Assemblers, interpreters, compilers translating
    a program into binary machine language
  • Linking editors, loaders create executable
    program by linking a machine language program
    with other separately translated binary program
    modules, built-in function libraries
  • Debuggers aid in tracing and debugging a
    program during its execution

40
Program Translation Process
Source
Object
Translator
Linker
Loader
Executable
41
Program Text Editors
  • Word processors format the appearance of the text
  • Text editors
  • Format the spacing between words for legibility
  • Ideal for structured languages
  • Text is the same font size
  • Examples
  • DOS Edit
  • Windows Notepad, Wordpad
  • Unix / Linux ed, vi, emacs
  • IDEs
  • MS Visual C, Symantec Visual Cafe

42
Programming Language Categories
  • Machine Language
  • Binary coded instructions
  • Assembly Language
  • Symbolic coded instructions
  • Procedural (High-Level) Languages
  • Procedural statements or arithmetic notation
  • Four-generation Languages
  • Natural language and nonprocedural statements
  • Object-oriented Languages
  • Combination of objects and procedures

43
Assembly Language
  • When to use
  • When speed or size of program is critical
  • Hybrid approach
  • Hardware Drivers
  • Can use specialized instructions
  • Disadvantages
  • Inherently machine specific
  • Architectures may become obsolete
  • Lack of programming structure

44
Assemblers
  • Binary code machine code
  • Hex code
  • Assembly Language
  • Mnemonic names ? op codes
  • Operations table (correspondence mnemonic
    instruction ? binary op code, number of operands,
    addressing mode)
  • Labels ? memory addresses
  • Comments
  • Symbol table (memory location for each
    instruction and label)
  • Memory Relocation (additional table for location
    adjustment at the time of execution)
  • Cross Assembler code prepared on one type of
    machine can be used on different type of machine

45
What Does This Program Do?
46
Assembly Instruction
Optional part
Comments
Operands
OpCode
Label
Mandatory part
00
0A Total LDR R3, 0 Clear R3. It will contain
the sum
- for decimal x for hexadecimal b for
binary
47
Assembly Instruction
  • Label symbolic name to identify memory location
    of the instruction
  • OpCode symbolic name of the instruction
  • Number of operands depends on the instruction
    (e.g., ADD R3,R3, R2)
  • Comments messages intended only for humans
    ignored by the assembler

48
Procedural Languages
  • COBOL
  • Wordy but easier to maintain
  • FORTRAN
  • Scientists and engineers
  • BASIC
  • Pascal
  • Highly structured teaching language
  • C
  • high-level commands and low-level access to
    hardware

49
Object-Oriented Languages
  • SmallTalk
  • C
  • Java
  • Based on C
  • Platform independent

50
Language Components
  • Lexicon
  • All legal words in the language
  • Meaning and type (verb, noun, preposition, etc.)
  • Syntax
  • Grammar rules
  • Sentence is grammatically correct
  • Semantics
  • meaning of the sentences as a whole

51
Compilers
  • Translates high-level language into low-level
    instructions
  • High-level language Source code
  • Machine-level Object code
  • Changes, including bug fixes, require recompiling

52
Source Code Instructions
  • Data declarations
  • Data type such as floating point, integer
  • Data operations
  • Instructions that update or compute data value
  • Control Structures
  • Branches, Goto, If-then-else, loops such as
    While-do and Repeat-until
  • Function, procedure, or subroutine calls
  • Receives control via a call instruction, receives
    and possibly modifies parameters, and returns
    control to the instruction after the call

53
Compilation Process
Updates internal tables
Checks for errors
Generates CPU instructions or library calls
54
Process of Parsing
  • Lexical analysis
  • Also known as scanning
  • Divides the string of input characters into
    single elements, tokens, based on strict computer
    punctuation
  • Syntactic analysis
  • Checks for errors in grammar rules
  • Semantic parsing
  • Determines the meaning of the string

55
Optimization
  • Compiler analyzes code in order to
  • Reduce amount of code
  • Eliminate repeated operations
  • Reorganize parts of the program to execute faster
    and more efficiently
  • Use computer resources more effectively
  • Example
  • Move outside the loop a calculation repeated
    within the body of the loop that does not use any
    value modified by the loop
  • Different compilers can produce different results!

56
Interpreters
  • Translates source code instructions into machine
    language and executes it one statement/line at a
    time
  • Disadvantages
  • Longer to execute, particularly bad for loops
  • Uses more memory
  • Advantage
  • Faster testing and code modification
  • Examples of interpreted languages
  • Java, BASIC, LISP

57
Interpreter vs. Compiler
Resources during execution Interpreter Compiler
Contents in memory
Interpreter/compiler Yes No
Source code Partial No
Executable code Yes Yes
CPU cycles
Translation operations Yes No
Library linking Yes No
Application program Yes Yes
58
Linking
Object file
Object file or object module
Executable file
Linker
C library
59
Linkers
  • Searches program libraries to find library
    routines used by the program
  • Library collection of pre-written functions and
    subroutines made available to perform commonly
    required activities
  • Determines the memory locations that code from
    each module will occupy and relocates
    instructions by adjusting absolute references
  • Resolves references among files

60
Why Link?
  • Construct single executable program from multiple
    object modules/code files compiled at different
    times
  • Program can be subdivided into components and
    parceled out to different developers
  • Example
  • Main program and multiple subroutines written and
    compiled by different programmers at different
    times

61
Loader
  • Loads binary files that have been linked into
    main memory
  • Program is ready for execution

62
Debuggers
  • Assembly language debuggers (to change the values
    in registers and memory locations)
  • Source code debuggers (work with high-level
    language statements)
  • Step through programs
  • Check variable values

63
Thank you!
Reading Lecture slides and notes, Chapters S2, 17
About PowerShow.com