Академический Документы
Профессиональный Документы
Культура Документы
Budditha Hettige
Department of Statistics and Computer Science University of Sri Jayewardenepura
Addressing
Budditha Hettige
Addressing
Subject of specifying where the operands (addresses) are
ADD instruction requires 2 or 3 operands, and instruction must tell where to find operands and where to put result
Addressing Modes
Methods of interpreting the bits of an address field to find operand
Immediate Addressing Direct Addressing Register Addressing Register Indirect Addressing Indexed Addressing
Budditha Hettige
Immediate Addressing
Simplest way to specify where the operand is Address part of instruction contains operand itself (immediate operand) Operand is automatically fetched from memory at the same time the instruction it self is fetched
Immediately available for use
Example
Immediate Addressing
MOV R1, #8 ; Reg[R1] 8 ADD R2R2, #3 ; Reg[R2] Reg[R2] + 3
Budditha Hettige
Direct Addressing
Operand is in memory, and is specified by giving its full address (memory address is hardwired into instruction) Instruction will always access exactly same memory location, which cannot change Can only be used for global variables who address is known at compile time
Example Instruction:
ADD R1, R1(1001) ; Reg[R1] Reg[R1] +Mem[1001]
Budditha Hettige
Budditha Hettige
Register Addressing
Same as direct addressing with the exception that it specifies a register instead of memory location Most common addressing mode on most computers since register accesses are very fast Compilers try to put most commonly accessed variables in registers Cannot be used only in LOAD and STORE instructions (one operand in is always a memory address)
Example instruction:
ADD R3, R4 ; Reg[R3] Reg[R3] + Reg[R4]
Budditha Hettige
Example instruction:
Budditha Hettige
Example
Following generic assembly program calculates the sum of elements (1024) of an array A of integers of 4 bytes each, and stores result in register R1
MOV R1, #0 MOV R2, #A MOV R3, #A+4096
; sum in R1 (0 initially) ; Reg[R2] = address of array A ; Reg[R3] = address of first word beyond A LOOP: ADD R1, (R2) ; register indirect via R2 to get operand ADD R2, #4 ; increment R2 by one word CMP R2, R3 ; is R2 < R3? BLT LOOP ; loop if R2 < R3
Budditha Hettige
10
Indexed Addressing
Memory is addressed by giving a register plus a constant offset Used to access local variables
Example instruction:
ADD R3, 100(R2)
; Reg[R3] Reg[R3] + Mem[100+Reg[R2]]
Budditha Hettige
11
Based-Indexed Addressing
Memory address is computed by adding up two registers plus an optional offset
Example instruction:
ADD R3, (R1+R2) ;Reg[R3] Reg[R3] + Mem[Reg[R1] + Reg[R2]]
Budditha Hettige
12
Instruction Types
ISA level instructions are divided into few categories
Data Movement Instructions
Copy data from one location to another
13
Budditha Hettige
14
15
Budditha Hettige
16
Budditha Hettige
17
Input / Output Instructions There are several input/output schemes currently used in personal computers
Programmed I/O with busy waiting Interrupt-driven I/O DMA (Direct Memory Access) I/O
Budditha Hettige
18
19
DMA I/O
DMA controller is a chip that has a direct access to the bus It consists of at least four registers, each can be loaded by software.
Register 1 contains memory address to be read/written Register 2 contains the count of how many bytes / words to be transferred Register 3 specifies the device number or I/O space address to use Register 4 indicates whether data are to be read from or written to I/O device
Budditha Hettige
20
Structure of a DMA
Budditha Hettige
21
22
Example
Writing a block of 32 bytes from memory address 100 to a terminal device (4)
Budditha Hettige
23
Example contd..
CPU writes numbers 32, 100, and 4 into first three DMA registers, and writes the code for WRITE (1, for example) in the fourth register DMA controller makes a bus request to read byte 100 from memory DMA controller makes an I/O request to device 4 to write the byte to it DMA controller increments its address register by 1 and decrements its count register by 1 If the count register is > 0, another byte is read from memory and then written to device DMA controller stops transferring data when count = 0
Budditha Hettige
24
Sample Questions
Q1.
1. Explain the processor architecture of 8086. 2. What are differences in Intel Pentium Processor and dual core processor. 3. What are the advantages and disadvantage of the multi-core processors
Budditha Hettige
25
Sample Questions
Q2. 1. What is addressing. 2. Comparing advantages, disadvantages and features briefly explain each addressing modes. 3. What is DMA and why it useful for Programming?. Explain your answer
Budditha Hettige
26