You are on page 1of 2

Takunda L.

C Dhlakama
CO794789A
Assignment 2
1. Write program in 8086 assembly language to count the occurrence of vowels in a given string.
You may assume that a 20 byte long string is available in the data segment of the program. [10]

MOV SI, 0
MOV DI, SI; DI counter for vowels

one: LEA DX, givenstring


MOV BH, 0AH;

two: COMP BH, vowels[DI]


JNE three
INC DI
JMP four

three:INC DI
DEC DH
JNZ two

four: INC SI
MOV DI,0
loop one
MOV AL, DL ; AL contains the number of vowels in the given string
RET

vowel db 'a','e','i','o','u'
Assuming DX contains the givenstring;
Assuming 'givenstring' is the string available in the data segement

2. What is the purpose of stack segment in an assembly program? How is the stack segment used
for implementing procedure call?[10]
Stack Segment is a 16 bit register used for storing the 64kb segemt of program stack, all data
referenced by the stack pointer and base point register is located in the stack segment. Stack
segment can be changed by the POP instruction.
The current address pointed to by the stack pointer is obtained by the the stack segemt and stack
point SS:SP, this is the stack top.
The stack segement contains variables,which will be pushed in and popped out during the
implementation of a call. The call procedure, transfers control to procedure, return address is
pushed to the stack. 4-byte address may be entered in this form: 1234h:5678h, first value is a stack
segment and the second is the instruction pointer. Prior to branching to the first instruction of the
called procedure, the CALL instruction pushes the address in the IP register onto the current stack.
This address is then called the return-instruction pointer and it points to the instruction where
execution of the calling procedure should resume following a return from the called procedure.
Upon returning from a called procedure, the RET instruction pops the return-instruction pointer
from the stack back into the EIP register. Execution of the calling procedure then resumes.

3.Can a machine have zero address instruction? If yes, then explain its functioning with an example.
If no, then explain why not.[5]
A machine can have a zero address instruction. It is used when an address is not needed to specify
the location of the operand. A zero-address machine is a stack-based machine where all operations
are done using values stored on the operand stack.
For example: PUSH B - pushes the value stored at memory location B onto the operand stack

4. Write a 8086 Assembly Language Program to sort an array of ten bytes in ascending order. Add
comments to your Program [10]

START: MOV AX,DATA


MOV DS,AX
MOV BX,size
DEC BX
program1: MOV CX,BX
MOV SI,0H
repeat1: MOV AL,A[SI] ; move value at address A[SI] to AL
INC SI ;increment SI
CMP AL,A[SI] ; compare value found at A[SI] to AL
JB program2
XCHG AL,A[SI]; exchange the contents of AL[SI] with contents for AL
MOV A[SI-1],AL
program2: LOOP repeat1
DEC BX
JNZ program1
RET

ASSUME CS:CODE, DS:DATA


Assuming that 10 random numbers are added to array A
size DB 10;setting the size of the array to 10

You might also like