Arithmetic Instructions and Indirect Operands-Assembly Language Programming-Lab Manual, Exercises of Assembly Language Programming

Prof. Abhay Aggrawal provided this lab handout for assistance at Birla Institute of Technology and Science for lab of Assembly Language Programming. It includes: Arithmetic, Architecture, Memory, Indexed, Addressing, Mnemonics, Experimental, Sign, Zero, Carry, Overflow

Typology: Exercises

2011/2012

Uploaded on 07/26/2012

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
2
EXPERIMENT NO 05
Arithmetic Instructions and Indirect Operands
1. Objectives
To use different arithmetic instructions available in 80x86 architecture
To study indirect operand types
2. Basic Information
Indirect Memory Operands
Like direct memory operands, indirect memory operands specify the contents of a given address.
However, the processor calculates the address at run time by referring to the contents of registers.
Since values in the registers can change at run time, indirect memory operands provide dynamic
access to memory.
Indirect memory operands make possible run-time operations such as pointer indirection and
dynamic indexing of array elements, including indexing of multidimensional arrays.
Strict rules govern which registers you can use for indirect memory operands under 16-bit
versions of the 8086-based processors. The rules change significantly for 32-bit processors
starting with the 80386. However, the new rules apply only to code that does not need to be
compatible with earlier processors.
2.1 Indirect Addressing
The operand is a register and register contains
an offset. In Real-address mode a 16-bit register
is used to hold the offset of a variable. If the register
is used as an indirect operand, it may only be SI, DI,
BX, or BP. Genrally we avoid BP because it addresses
the stack rather than the data segment. In the example below
we use SI to refernce val1:
.data
val1 BYTE 10h
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset val1
mov al,[si] ;AL=10h
36B4 0A00
36B4
0A00
R1
R2
main memoryregisters
MOV R1, (R2)
docsity.com
pf3
pf4

Partial preview of the text

Download Arithmetic Instructions and Indirect Operands-Assembly Language Programming-Lab Manual and more Exercises Assembly Language Programming in PDF only on Docsity!

EXPERIMENT NO 05

Arithmetic Instructions and Indirect Operands

1. Objectives

 To use different arithmetic instructions available in 80x86 architecture

 To study indirect operand types

2. Basic Information

Indirect Memory Operands

Like direct memory operands, indirect memory operands specify the contents of a given address. However, the processor calculates the address at run time by referring to the contents of registers. Since values in the registers can change at run time, indirect memory operands provide dynamic access to memory. Indirect memory operands make possible run-time operations such as pointer indirection and dynamic indexing of array elements, including indexing of multidimensional arrays. Strict rules govern which registers you can use for indirect memory operands under 16-bit versions of the 8086-based processors. The rules change significantly for 32-bit processors starting with the 80386. However, the new rules apply only to code that does not need to be compatible with earlier processors.

2.1 Indirect Addressing

The operand is a register and register contains an offset. In Real-address mode a 16-bit register is used to hold the offset of a variable. If the register is used as an indirect operand, it may only be SI, DI, BX, or BP. Genrally we avoid BP because it addresses the stack rather than the data segment. In the example below we use SI to refernce val1:

.data val1 BYTE 10h .code main proc mov ax,@data mov ds,ax mov si,offset val mov al,[si] ;AL=10h

36B4 0A

36B 0A

R R

registers main memory

MOV R1, (R2)

2.2 Arrays

Indirect operands are particularly useful when dealing with arrays because an indirect operands value can be modified. Similar to an array subscript, an indirect operand can point to different array element. For example, arrayB contains three byte. We can increment SI and make it point to each byte, in order:

.data arrayB BYTE 10h, 20h, 30h .code mov si , OFFSET arrayB mov al,[si] ;AL=10h inc si mov al,[si] :AL=20h inc si mov al,[si] ;AL=30h

if we use an array of 16 bit integers, we add 2 to SI to address each subsequent array element: .data arrayW word 1000h, 2000h, 3000h .code mov si , OFFSET arrayW mov ax,[si] ;AX=1000h add ax, mov ax,[si] :AX=2000h add ax, mov ax,[si] ;AX=3000h

2.3 Indexed Addressing

In indexed addressing the operand adds a constant to generate an effective address. The registers that are used as indexed operands are SI, DI, BX, or BP. The index register should be initialized to zero before accessing the first array element: e.g., .data arrayB BYTE 10h, 20h, 30h .code mov si ,0 ;SI initialized to zero mov al,array[si] OR mov al,[arrayB+si] ;AL=10h inc si mov al,array[si] OR mov al,[arrayB+si] ;AL=20h inc si mov al,array[si] OR mov al,[arrayB+si] ;AL=30h

36B4 0A

36B 0800

R R

registers main memory

MOV R1, (0200 + R2)

0200

Question 3: Define following in the data segment .data String1 BYTE “ABCDEFGHIJ” String2 BYTE 10 DUP(?)

Write a Program that copies the contents of String1 to String2 and reverse the order. For example at the end the contents of String2 should be “JIHGFEDCBA”.

Assemble, Link and Debug the Program. From memory window see the contents of String1 and String2 and fill the following memory map table.

Address Content Address Content Address Content

Source Array1 Source Array 2 Destination Array

Address Content Address Content

Original String Copied String