1 / 63

Lecture 7:

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

buzz
Télécharger la présentation

Lecture 7:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 1000 “Introduction to Information Technology” Lecture 7: 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. Source REGISTER Destination REGISTER OPCODE Register Instruction ADDRESS 2 ADDRESS 1

  7. Register Addressing *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

  12. 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

  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

  14. Op code Destination register IBM zSystem Example: Load • Instruction Word Base register 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

  17. Fetch-Execute Cycle for Relative Address: ADD Instruction

  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

  22. Fetch-Execute Cycle for Immediate Addressing: Load Instruction

  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

  24. 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

  25. Fetch-Execute Cycle for Indirect Addressing: Load Instruction

  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. Instruction in location 07 treated as data, incremented, and replaced to its original location Totalizer Loop with Direct Addressing

  28. 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 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

  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

  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 Translator Object 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 [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

  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

More Related