Indexing and Arrays
Index mode – the effective address of the operand is generated by
adding a constant value to the contents of a register.
Index mode is represented as X(Ri)
EA = X + [Ri]
The constant X may be given either as an explicit number or as a
symbolic name representing a numerical value.
If X is shorter than a word, sign-extension is needed.
Indexing and Arrays
Index mode: X(Ri)
EA = X + [Ri]
ADD 20(R1), R2
R1=1000
EA= 20+1000=1020
Indexing and Arrays
In general, the Index mode facilitates access to an operand
whose location is defined relative to a reference point within
the data structure in which the operand appears.
Several variations of index mode:
1)(Ri, Rj)- Base with Index mode
EA = [Ri] + [Rj]
2)X(Ri, Rj) – Base index with offset mode
EA = X + [Ri] + [Rj]
Relative Addressing
Relative mode – the effective address is determined by the Index mode
using the program counter in place of the general-purpose register.
X(PC) – note that X is a signed number
This mode is used to specify the target address in branch instructions.
Branch>0 LOOP
This location is computed by specifying it as an offset from the current
value of PC.
Branch target may be either before or after the branch instruction, the
offset is given as a signed num.
Addressing Modes
Relative Address
0
EA = PC + Relative Addr 1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Additional Modes
Autoincrement mode – the effective address of the operand is the contents of a
register specified in the instruction. After accessing the operand, the contents of
this register are automatically incremented to point to the next item in a list.
(Ri)+. The increment is 1 for byte-sized operands, 2 for 16-bit operands, and 4
for 32-bit operands.
Autodecrement mode: -(Ri) – Contents of the register specified in the instruction
is decrement first and then used as the effective address of the operand
Move N,R1
Move #NUM1,R2 Initialization
Clear R0
LOOP Add (R2)+,R0
Decrement R1
Branch>0 LOOP
Move R0,SUM
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Addressing Modes
Name Assembler syntax Addressing
function
The different
ways in which Immediate #Value Operand= Value
the location of
an operand is Register Ri EA = Ri
specified in Absolute(Direct) LOC EA = LOC
an instruction
are referred to Indirect (R i ) EA = [Ri ]
as addressing (LOC) EA = [LOC]
modes.
Index X(R i) EA = [Ri ]+ X
Basewithindex (R i,R j ) EA = [Ri ]+ [Rj ]
Basewithindex X(R i,R j ) EA = [Ri ]+ [Rj ] + X
andoffset
Relative X(PC) EA = [PC] + X
Autoincrement (R i)+ EA = [Ri ] ;
Increment R i
Autodecrement (R i ) Decrement R i ;
EA = [Ri]
Assembly Language
Assembly Language
A Complete set of mnemonics (symbolic names) and rules for
their use constitute a programming language, referred to as an
Assembly Language.
The set of rules for using mnemonics in the specification of
complete instructions and programs is called the syntax of the
language.
Assembler is a collection of programs that are a part of system
software which converts(translates) programs written in
assembly language into a sequence of machine instructions.
Assembly Language
The user program written using alphanumeric text format is
called as Source Program.
The assembled machine language program is called as
object program.
Assembler Directives:
• These are the instructions given to the assembler while it
translates a source program to object program.
• These are not converted into object program.
• Some of the assembler directives are : EQU, ORIGIN,
DATAWORD
Assembler Directives:
EQU(equate):
This is used to define a constant value or a fixed address.
The EQU directive does not set aside storage for a data item,
but associates a constant number with a data or an address
label so that when the label appears in the program, its
constant will be substituted for the label.
Assembler Directives:
ORIGIN:
The origin directive tells the assembler where to load
instructions and data into memory.
It changes the program counter to the value specified by the
expression in the operand field.
Subsequent statements are assembled into memory locations
starting with the new program/location counter value.
If no ORG directive is encountered in a source program, the
program counter is initialized to zero.
Assembler Directives:
DATAWORD:
This directive is used to load a value into the memory location.
RESERVE :
This directive is used to reserve a memory block for data and
also associates a name to the block
START:
It is the address of the location at which the execution of the
program is to begin
END
Tells the assembler that this is the end of the source program.
Assembly and Execution of programs
Instruction
Format:
Label Operation Operand(s) Comment
Loader:
The loader is a system software program that loads the object
program from magnetic disc to the memory of a computer.
Debugger:
This is another system software program that detects and
reports the syntax errors to the user.
Number Notation
A decimal number is directly represented as
ADD #93,R1
A binary number is identified by a prefix symbol %(percent
sign)
ADD #%01011101,R1
A hexadecimal number is identified by a prefix symbol $(dollar
sign)
ADD #$5D,R1