You are on page 1of 12

Computer Organization

and
Assembly Language
Lab 07
BSCS III
Engr Muneeba Mubarik
Query

Source index
1
reg
2
3
4
Arrays in assembly language

Arrays:
Collection of characters in sequence.

Why do we study arrays?

To store multiple values in sequence with single variable name


For example: var db 12345678
General syntax to initialize arrays in program

.model small
.stack 100h
.data
arr db 1,2,3,4,5
arr db ‘m’,’u’,’s’,’a’
arr db ‘musa’
arr db 3 dup(’z’)
arr db ?,?,?,?
arr db 4 dup(‘?’)

.code
Main proc
Source Index Register

Why we need SI register?

To access array, it will act as pointer

Syntax:

Mov si, offset arr (offset gives starting address or address of first value)
Mov dx, [si] (use bracket to access value else it will give address to dx)
Mov ah,2
Int 21h
Inc si
Task

WAP that prints the following array:


‘h’,’o’,’p’,’e’
Array using loop
Syntax:
Mov cx,8
A1:
Mov dx,[si]
Mov ah,2
Int 21h
Inc si
Loop A1
Mov ah,4ch
Int 21h
Main endp
Task

WAP that prints array ‘c’,’o’,’m’,’p’,’u’,’t’,’e’,’r’ using loop.

WAP that prints array 5 10 times using loop.

WAP that input vowels and print array using loop.


Maximum no and Minimum no in
array
.data
arr db 7,3,5,4,2
.code
main proc
Mov ax, @data Loop L1
Mov ds,ax Add bl,48
Mov si,offset arr Mov dl,bl
Mov cx,5 Mov ah,o2h
Mov bl, [si] Int 21h
L1: Large:
Cmp [si],bl Mov bl,[si]
Jge large Jmp compare
Compare:
Inc si
main endp
end main
Take user input in array
.data
arr db 5 dup(?)
.code
main proc
mov ax, @data mov si,offset arr
mov ds,ax mov cx,5
mov si,offset arr L2:
mov cx,5 mov dl, [si]
mov bl, [si] mov ah,02h
L1: int 21h
mov ah,01h mov dl, 32
int 21h mov ah,02h
mov [si], al int 21h
inc si inc si
Loop L1 loop L2
main endp
end main
Nested loop example
. .model small
.stack 100h
.data
.code
main proc mov bx, 1 mov dl,10
mov ah, 2
mov cx, 5 int 21h
L1: mov dl,13
push cx mov ah, 2
mov cx, bx int 21h
inc bl
L2:
Mov dl, '*' pop cx
mov ah,2 loop L1
main endp int 21h
end main loop L2
Home task

Solve Assignment 02 & Prepare the topic for Quiz.

You might also like