4-Oct-0194.201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 20011  direct mode: OK for static addresses  indirect register mode:

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

CPU Review and Programming Models CT101 – Computing Systems.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
There are two types of addressing schemes:
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Assembly Programming Notes for Practical2 Munaf Sheikh
Instruction Set Architecture
Addressing modes The way in which an operand is specified is called the Address Mode.
1/2002JNM1 AL 00 Immediate Addressing Mode Mov AL, 3CH AL 3C.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
8086 Assembly Language Programming I
Addressing modes – 1 The way in which an operand is specified is called the Address Mode.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Part II: Addressing Modes
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
Stack Operations LIFO structure (last-in,first-out) –The last value put into the stack is the first value taken out Runtime stack –A memory array that.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Types of Registers (8086 Microprocessor Based)
30-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Problem: must convert ideas (human thoughts) into an executing.
Execution of an instruction
1 ICS 51 Introductory Computer Organization Fall 2009.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
SYSC 2001*: copyright ©T. Pearce, D. Hutchinson, L. Marshall Nov Virgo lectures- revised Nov. 14, Virgo Ch. 11 of Stallings has been incorporated.
Microprocessor Microprocessor (cont..) It is a 16 bit μp has a 20 bit address bus can access upto 220 memory locations ( 1 MB). It can support.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Addressing Modes. Addressing Mode The data is referred as operand. The operands may be contained in registers, memory or I/O ports, within the instruction.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Internal Programming Architecture or Model
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Stack Operations Dr. Hadi AL Saadi.
Instruction set Architecture
Format of Assembly language
Part of the Assembler Language Programmers Toolbox
94201.lecture19-22-subroutines
ADDRESSING MODES.
Microprocessor and Assembly Language
Assembly IA-32.
ADDRESSING MODES.
Processor Processor characterized by register set (state variables)
(The Stack and Procedures)
Assembly Lang. – Intel 8086 Addressing modes – 1
Chapter 3 Addressing Modes
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Computer Organization and Assembly Language (COAL)
Microprocessor and Assembly Language
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
8086 Registers Module M14.2 Sections 9.2, 10.1.
(Array and Addressing Modes)
(The Stack and Procedures)
(Array and Addressing Modes)
CNET 315 Microprocessor & Assembly Language
Lecture 06 Programming language.
Process.
(The Stack and Procedures)
Computer Organization and Assembly Language
(The Stack and Procedures)
(Array and Addressing Modes)
Presentation transcript:

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  direct mode: OK for static addresses  indirect register mode: OK for dynamic addresses to access byte or word must have exact address in register  need more powerful modes for data structures What is a data structure? Indirect Addressing

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  composite structures: collections of elements  array: elements are all of the same type in high-level language access using [ ]  selector, e.g. X[ i ]  record (struct): may include elements of different types e.g.struct student { string Name; int ID; } in high-level language access using “.” selector, e.g. X.Name  arrays of structures e.g. 201Class[ i ].Name  stack: more later! want dynamic access to elements Indirect Addressing: Data Structures

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Arrays:  start address is fixed  elements are stored sequentially  all elements are of same type fixed memory requirement for each element constant offset (# or bytes) to start of next element  2 relevant cases in programming: address of array is static address of array is dynamic Indirect Addressing: Arrays

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept address of array is static writing program for a specific array –e.g. arrayX in assignment 3 2.address of array is dynamic writing program for “any” array –e.g. a function that processes an array and accepts the array as an argument –different invocations of the function may process different arrays  addressing modes exist to support both cases ! Indirect Addressing: Arrays (Cont.)

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  use when accessing array using static address  like register indirect, except also specify a constant e.g. [ BX + constant ]  during execution, processor uses a temporary register to calculate BX + constant  accesses memory addressed by BX + constant  restriction: may only use BX, BP, SI or DI (as for register indirect)! Indirect Addressing: (Indirect) Indexed Addressing Mode

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  to use in accessing an array: start address of array is the constant use register to hold index –index = offset (in bytes) to specific element e.g. suppose have array of integers declared: X:DW; 1 st element of array DW; 2 nd element of array...; etc. SizeOfX:DW ; number of elements in X  each element is 2 bytes long! Indirect Addressing: (Indirect) Indexed Addressing Mode (Cont.)

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept ; sum the contents of array X into AX MOVAX, 0; initialize sum MOVBX, 0; initialize array index MOVCX, [SizeOfX] ; get # of elements CheckForDone: CMPCX, 0; any elements left to sum? JEDone ADDAX, [ BX + X ]; sum i th element ADDBX, 2; adjust index (offset) SUBCX, 1; one less element JMPCheckForDone Done:; at this point: AX = sum of elements BX = address of byte that follows array X in memory CX = 0 Indirect Indexed Addressing: Code Fragment Example X is static; BX is dynamic offset

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  overflow? what if sum exceeds capacity of AX? what conditions should be tested? why? JO vs. JC ??  could the control flow be more efficient? ; set up AX, BX, CX as before CMPCX, 0; any elements left to sum? JEDone SumElement: ADDAX, [ BX + X ]; sum i th element ADDBX, 2; adjust index (offset) SUBCX, 1; one less element JNZSumElement Done:  Eliminated 2 instructions from the loop, and used one byte less memory (JNZ vs JMP) Indirect Indexed Addressing: Example (Cont.) Don’t do CMP, flags set by SUB

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  could the control flow be even more efficient ? adjust CX only at start of loop execution? adjust CX only at end of loop execution? ; set up AX, BX, CX as before CheckForDone: SUBCX, 1; any elements left to sum? JCDone ADDAX, [ BX + X ]; sum i th element ADDBX, 2; adjust index (offset) JMPCheckForDone Done: Or: ; set up AX, BX, CX as before JMP CheckForDone SumElement: ADDAX, [ BX + X ]; sum i th element ADDBX, 2; adjust index (offset) CheckForDone: SUBCX, 1; one less element JAE SumElement Done: Indirect Indexed Addressing: Efficiency

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  to access array using dynamic address  like indexed, except use a register instead of a constant e.g. [ BX + SI ]  during execution, processor uses a temporary register to calculate sum of register values  accesses memory addressed by sum  restrictions:  one must be base register: BX or BP  one must be index register: SI or DI  the only legal forms: [ BX + SI ] [ BX + DI ] [ BP + SI ] [ BP + DI ]  often, the start address of an array is supplied as an argument to a function put this value in one register  use other register to hold offset (index) into array Indirect Addressing: (Indirect) Based Addressing Mode

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept ; assume BX = start address of array, ; and CX = number of array elements ; now sum the contents of array into AX MOVAX, 0; initialize sum MOVSI, 0; initialize array index CheckForDone: CMPCX, 0; any elements left to sum? JEDone ADDAX, [ BX + SI ] ; sum i th element ADDSI, 2; adjust index (offset) SUBCX, 1; one less element JMPCheckForDone Done:; at this point: AX = sum of elements Indirect Based Addressing: Code Fragment

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  like based, except include a constant too e.g. [ BX + SI + constant ]  during execution, processor uses a temporary register to calculate sum of values  accesses memory addressed by sum  restrictions: same as based mode  if start address of array of arrays is known: use start address as constant use one register as offset to start of sub-array use other register as index  if start address is not known ???? wing it! Indirect Addressing: (Indirect) Based- Indexed Addressing Mode

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  like based, except include a constant too e.g. [ BX + SI + constant ]  during execution, processor uses a temporary register to calculate sum of values  accesses memory addressed by sum  restrictions: same as based mode  if start address of array of arrays is known: use start address as constant use one register as offset to start of sub-array use other register as index  if start address is not known, wing it!  if array of structures: use one register for start address use one register as offset to start of structure use constant to select element  that’s all for (indirect) addressing modes! Indirect Addressing: (Indirect) Based- Indexed Addressing Mode

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  How “mechanics” of processor work is one thing – using them in programs is another Example: Stack  a data structure  often used to hold values temporarily Concept:  a “stack” is a pile of “things” e.g. a stack of papers  one “thing” is on top the rest follow beneath sequentially  can add or remove “things” from top of pile  if add a new “thing”, it is now on top (change state)  if remove a “thing” from the top, then “thing” that was below it in the pile is now on top (read state)  can look at a thing in the stack if you know the position of the thing relative to the top e.g. 2 nd thing is the one below the top Stacks

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  stack holds “values”  reserve a block of memory to hold values  use a pointer to point to the value on top General case of operation:  pointer points to value on top of stack  add: 1. adjust pointer to next free (sequential) memory location 2.copy value to selected memory location (becomes new top)  remove: 1. copy value of current top 2.adjust pointer to point to value “beneath” current top (becomes new top)  read: index from top pointer to i th item Stacks: Implementation in a Computer

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Stacks: Implementation in a Computer top pointer item on top next item last item unused locations items in stack block of memory next location for adding a value

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  empty stack (no items in stack) what should top pointer point to? implementation: usually points just outside the reserved block – next add will adjust pointer before copying value – will copy into location in the block  full stack (no space to add more items) what should happen if an item added? implementation could: –check for stack overflow (?) (exception handling!) –happily overwrite memory outside of reserved block (?)  Issue: Should stack grow from high-to-low addresses (as drawn in picture), or vice versa ? conceptually: no difference implementation: typically grows high-to-low (reasons later!) Stacks: Implementation: Special Cases

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Processor has built-in stack support:  called hardware or run-time stack  dedicated pointer register: SP some instructions use run-time stack implicitly via SP  stack holds 16-bit values  grows “down” in memory (high-to-low addresses) (Built-In) Stack Operations: PUSHadds a new item at top of stack must specify 16-bit source operand operand may be register or memory grows “down”effective execution: SP := SP – 2// adjust pointer mem[SP] := operand// copy value to top Stacks: p86 Stack

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept POPremoves item from top of stack  must specify 16-bit destination operand operand may be register or memory  effective execution: operand := mem[SP]// copy value to top SP := SP + 2// adjust pointer could use any of BP, BX, SI, DI Read an item: must index from top [SP + constant ] isillegal!!! common solution uses BP (reason for BP in 203!) MOVBP, SP; copy top pointer access using [BP + constant] is legal! Stacks: p86 Stack (Continued)

4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Note: Must initialize SP before using stack operations: e.g. MOVSP, 0FFFEH Example: suppose need to save registers: PUSHAX PUSHBX PUSHCX now … to access saved AX value: could POP values off until AX value reached, OR: MOVBP, SP +2 MOV …, [ BP + 4 ] ; read saved AX +4 Stacks: p86 Stack (Continued) AX value BX value CX value SP AX value BX value CX value SP BP AX value BX value CX value SP BP