630 likes | 853 Views
ITEC 1000 “Introduction to Information Technology”. Lecture 7:. Instruction Addressing and Programming Tools. { Prof. Peter Khaiter }. Lecture Template:. Direct, Absolute Addressing Register Addressing Base Register Addressing Relative Addressing Direct Addressing and Alternatives
E N D
ITEC 1000 “Introduction to Information Technology” Lecture 7: Instruction Addressing and Programming Tools {Prof. Peter Khaiter}
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
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
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
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)
Source REGISTER Destination REGISTER OPCODE Register Instruction ADDRESS 2 ADDRESS 1
Register Addressing *Done in parallel with the move; only 3 time units required
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
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)
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
IBM zSystem • Base register address creation
IBM zSystem: Load Instruction • 16 64-bit general-purpose registers • Load instruction format GP register holds the base address value Destination GP register to get data from memory
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
Op code Destination register IBM zSystem Example: Load • Instruction Word Base register Displacement/Offset
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
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
Alternatives to Direct Addressing • Immediate addressing • Indirect addressing • Register Indirect addressing • Indexed addressing
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
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
Fetch-Execute Cycle for Immediate Addressing: Load Instruction
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
Indirect Addressing addressing mode (2=indirect addressing) address field op code 0001 0010 0011 0101 (the number 05) (Load) Destination register (R3) Memory 0111: 0000 0101 0111
Fetch-Execute Cycle for Indirect Addressing: Load Instruction
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
Instruction in location 07 treated as data, incremented, and replaced to its original location Totalizer Loop with Direct Addressing
Asterisk used to indicate indirect instruction Totalizer Loop with Indirect Addressing
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
Register Indirect Addressing: Duel Duty • Autoincrementing/autodecrementing • Direct implementation of C’s “++” 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
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)
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
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)
Programming Tools • Editors • Assemblers • Debuggers • Compilers • Linking editors • Loaders • Interpreters Integrated Development Environments (IDEs) combine several of the above programming tools
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
Program Translation Process Source Translator Object Linker Loader Executable
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
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
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
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
Assembly Instruction Optional part [Label] OpCode Operands [; Comments] Mandatory part 00 : 0A Total LDR R3, #0 ; Clear R3. It will contain the sum # - for decimal; x – for hexadecimal; b – for binary
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
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
Object-Oriented Languages • SmallTalk • C++ • Java • Based on C++ • Platform independent
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