The Pointer Register - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

The Pointer Register

Description:

We look at an example where a sequence of consecutive elements in memory are accessed. ... A pointer register holds a variable that is the address of a variable ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 19
Provided by: alancl6
Category:
Tags: pointer | register

less

Transcript and Presenter's Notes

Title: The Pointer Register


1
The Pointer Register
  • This presentation demonstrates how a pointer
    register is used to implement address register
    indirect addressing.
  • We look at an example where a sequence of
    consecutive elements in memory are accessed.

2
Memory address and data
  • A memory consists of a sequence of consecutive
    locations.
  • Each location has a byte address.
  • A single byte is stored in each location
  • The notation 1234 25 means that the contents
    of memory location 1234 is the value 25.

3
Instructions and Notation
  • We will assume a register-based three instruction
    format.
  • The operation ADD R1,R2,R3 adds the contents of
    register R3 to register R2 and puts the result in
    register R1.
  • All destination (result) operands will be in bold
    fond to improve readability.
  • The notation n in an instruction means the
    number n not the memory location n.
  • The notation R1 in an instruction means that R1
    contains the address of the operand in memory.

4
Memory Structure
We can write 100716 76
5
The Problem
  • We want to add together the ten numbers in
    consecutive memory locations 100016 to 100916.
  • A simple algorithm is
  • Sum Number1000
  • Repeat
  • Sum Sum Numbernext
  • Until allNumbersAdded

6
Adding the Numbers
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
This sequence continues until all numbers have
been added.
7
The Pointer Register
The next step is to introduce the pointer
register. A register holds a variable. A pointer
register holds a variable that is the address of
a variable in memory. When you access data via a
pointer register, you access the data being
pointed at by the register.
8
The Pointer Register
Register R1 contains the value 100016. The number
in R1 is the address of the first number in the
list. Register R1 is said to point at the
location it contains.
Register R1 points at the element 04.
9
Accessing Memory via a Pointer
A typical memory register indirect memory access
is written LOAD R2,R1 This means load register
R2 with the contents of the memory location whose
address is in R1.
We can represent this action in register transfer
language as R2 ? R1
10
Incrementing the Pointer
Suppose we add 1 to the contents of the pointer
register with an instruction like ADD R1,R1,1
After the addition, the pointer register now
contains 100116.
11
Pointing to the Next Element
Because we added 1 to the pointer, register R1 is
now pointing at the next element in the sequence.
Because we added 1 to the pointer, register R1
contains 100116 and is now pointing at the next
element in the sequence.
12
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
13
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
14
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
15
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
16
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
17
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,,R2R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
18
The Algorithm in Machine Code
Sum Number1000 Repeat Sum Sum
Numbernext Until allNumbersAdded
LOAD R1,100016 Register R1 points to
the numbers LOAD R2,R1 Register R2
holds the first number Repeat ADD
R1,R1,1 Register R1 points to the next number
ADD R2,R2,R1 Add the number pointed at by
R1 to the sum CMP R1,100916 Are we at
the last memory location? BNE
Repeat If not last number then repeat.
Write a Comment
User Comments (0)
About PowerShow.com