0% found this document useful (0 votes)
68 views6 pages

Practical Lab 8

This document discusses an experiment on data manipulation and indexing in assembly language. It includes: 1. The objectives are to introduce basic arithmetic instructions, use of the ASCII table, and array manipulation. 2. The ASCII table assigns a numeric code to each character. Codes can be expressed in decimal or hexadecimal. Arrays can be declared and initialized using directives like DB, DW, and DUP. 3. Indexing modes like based, indexed, and based-indexed addressing are demonstrated to access array elements. An example program prompts the user to input two numbers, calculates their sum, and displays the result.

Uploaded by

Vishal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views6 pages

Practical Lab 8

This document discusses an experiment on data manipulation and indexing in assembly language. It includes: 1. The objectives are to introduce basic arithmetic instructions, use of the ASCII table, and array manipulation. 2. The ASCII table assigns a numeric code to each character. Codes can be expressed in decimal or hexadecimal. Arrays can be declared and initialized using directives like DB, DW, and DUP. 3. Indexing modes like based, indexed, and based-indexed addressing are demonstrated to access array elements. An example program prompts the user to input two numbers, calculates their sum, and displays the result.

Uploaded by

Vishal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of: Subject of:

Computer Systems Engineering Computer Architecture and Assembly


Programming
Mehran University of Engineering Year 2nd Semester 3rd
&Technology
Batch 19CS Duration 03
Hours
Jamshoro

Practical no#08

To Become familiar with Indexing and Data Manipulation

Introduction:

In this experiment you will be introduced to data transfer and arithmetic instructions.
You will also deal with indexing, and array manipulation.

Objectives:

1- Basic arithmetic instructions


2- Use of the ASCII table.
3- Manipulation of arrays

ASCII code Table:

The ASCII table is a double entry table, which contains all alphanumeric characters
and symbols. Each symbol, or character, has its own ASCII code. This code can either
be in decimal or hexadecimal format. The code of a given character is found by
concatenating the column number with the row number, if the code is to be expressed
in hexadecimal. The row number is to be the least significant. For the same code to be
expressed in decimal, the row number is added to the column number (See example
given below).

As an example, the symbol’ $’ is at the intersection of row 4 and column 2, therefore


its ASCII code is 24H. The decimal equivalent of this code can be found by adding 4
to 32, which yields 36.

The following tables show the ASCII codes (Table 8.1), and examples on the use of
the ASCII table (Table 8.2), and how to calculate the ASCII codes for different
characters and symbols.
Table 8.1: ASCII Table

Character Column # Row # Code (H) Code (10)


a 6 1 61 96 + 1 = 97
A 4 1 41 64 + 1 = 65
 E 1 E1 224 + 1 = 225
% 2 5 25 32 + 5 = 37

Table 8.2: Examples on the use of the ASCII table:

Note on the use of arrays:

The DB and DW directives are respectively used to declare a variable of size byte or
word. The following declaration defines a variable X of size byte and assigns it the
value 10H.
X DB 10H

Identically the following will define a variable of size word, and assigns it the value

13EFH: Y DW 13EFH
The DUP directive may be used to reserve more than one consecutive data item and
initialize reserved items to the same value. For example, the instruction:

ByteArray DB 100 DUP(0)

Instructs the assembler to reserve an array of 100 bytes, and initializes each byte to the
value zero. If the “0” in the above declaration is replaced with “?”, the assembler will
not initialize the bytes of the array to any value.

To access the different elements of an array, we use one of the following addressing
modes (See practical no.07).

- Based addressing mode.


- Indexed addressing mode.
- Based-Indexed addressing mode.

The Based-Indexed addressing mode may be used to access a two-dimensional array.


Here are examples of each case.

Array1 DB 0,1,2,3,4,5,6,7,8,9
Array2 DB 10 DUP(0)
Array3 DB 11,12,13,21,22,23,31,32,33
RowSize EQU 3

Based addressing mode:

MOV BX, OFFSET Array1 ; Address Array1


MOV AL,[BX+4] ; Access 5th element of Array1

Indexed addressing mode:

MOV DI, OFFSET Array2 ; Address Array2


MOV [DI+6],AL ; Copy to 7th element of Array2
MOV SI,3
MOV Array2[SI],AL ;Copy to 4th element of Array2

Based-Indexed addressing mode:

MOV BX, OFFSET Array3 ; Address Array3


MOV SI,1*RowSize ; Beginning of 2nd row
MOV DI,2*RowSize ; Beginning of 3rd row
MOV AL, [BX+SI+1] ; Access 2nd element of 2nd row
MOV [BX+DI+2],AL ; Access 3rd element of 3rd row

Remark:

Notice that row R, has index (R-1), and element n has index (n-1).
Pre Lab Work:

1. Study programs 8.1 and 8.2, and review the material related to indexing
and data manipulation.
2. Write both programs and see how program 8.1 manipulates the variables in
internal registers, and how program 8.2 uses memory for the same purpose.

Lab Work:

.
1- How many digits can you enter each time? Explain this.
2- What happens when the sum exceeds 9? Explain this.

Lab Assignment:

Write a program that prompts the user to enter a number Then the program checks
whether the entered number is Prime number or not?
TITLE "PROGRAM 1 EXPERIMENT 8"

; This program reads two numbers from the keyboard and


; gives their sum. This program uses internal registers
; to store the variables.

.MODEL SMALL
.STACK 200
.DATA
CRLF DB 0DH,0AH,'$'
PROMPT1 DB 'Enter the first positive integer: ','$'
PROMPT2 DB 'Enter the second positive integer: ','$'
PROMPT3 DB 'The sum of the two numbers is: ','$'
.CODE
.STARTUP
LEA DX,PROMPT1 ;DISPLAY PROMPT1
MOV AH,09H
INT 21H

MOV AH,01H ;READ FIRST NUMBER


INT 21H
SUB AL,30H ;Convert character to number
MOV CL,AL ;SAVE THE NUMBER IN CL

LEA DX,CRLF ;MOVE CURSOR TO NEXT LINE


MOV AH,09H
INT 21H
LEA DX,PROMPT2 ;DISPLAY PROMPT2
MOV AH,09H
INT 21H

MOV AH,01H ;READ SECOND NUMBER


INT 21H
SUB AL,30H ;Convert character to number
ADD AL,CL ;PERFORM ADDITION AND SAVE RESULT IN CL

MOV CL,AL
ADD CL,30H ;CONVERT DIGIT TO CHARACTER

LEA DX,CRLF ;MOVE CURSOR TO NEXT LINE


MOV AH,09H
INT 21H
LEA DX,PROMPT3 ;DISPLAY PROMPT3
MOV AH,09H
INT 21H

MOV DL,CL ;DISPLAY SUM


MOV AH,02H
INT 21H
.EXIT
END
TITLE "PROGRAM 2 EXPERIMENT 8"

You might also like