Tutorial 7

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

MPI Tutorial 7

27.02.2024
28.02.2024
29.02.2024
04.03.2024
Problem 1

Q1. Write an ALP to accept two numbers in two registers


using the equate directive and swap them.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution

TEN EQU 10
NINE EQU 9

MOV AL,TEN
MOV BL,NINE

PUSH AX ; store value of AX in stack.


PUSH BX ; store value of BX in stack.

POP AX ; set AX to original value of BX.


POP BX ; set BX to original value of AX.

RET

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 2

Q2. Find out the Content of the following registers on executing the ALP: AX, BX, DS/ES

(a) (b)
.MODEL SMALL .MODEL SMALL
.DATA .DATA
VAR DB 23h,45H,00H,98H
VAR DB 23h,45H,00H,98H

.code
.code
LEA BX, VAR
LEA BX, VAR
LDS AX, VAR LES CX, VAR
RET
RET

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution

(a)

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution

(b)

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 3

Q3. Write an assembly language program to convert 8-bit binary data to BCD utilizing the given flowchart.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution
MOV BX,1100H ;Load the address of the data in BX-register.
MOV AL,[BX] ;Get the binary data in AL-register.
MOV DX,0000H ;Clear DX for storing hundreds and tens.
HUND: CMP AL,64H ;Compare whether data is less than 100 (or 64H).
JC TEN ;If the data is less than 100 then jump to TEN.
SUB AL,64H ;If data greater than 100, subtract hundred.
INC DL ;Increment hundreds register.
JMP HUND ;Repeat subtraction of hundred.

TEN: CMP AL,0AH ;Compare whether data is less than 10 (or 0AH).
JC UNIT ;If data is less than 10 then jump to UNIT.
SUB AL,0AH ;If data greater than 10 then, subtract ten.
INC DH ;Increment tens register.
JMP TEN ;Repeat subtraction of ten.

UNIT: MOV CL,4 ;Rotate tens digit to upper nibble position.


ROL DH,CL
ADD AL,DH ;Combine tens and units digit.
MOV [BX+1],AL ;Save tens and units in memory.
MOV [BX+2],DL ;Save hundreds in memory.

HLT ;Halt program execution.


8

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 4

Q4. Find
the content of stack and SP after the execution of following instruction. Assume CS = 700H, SS = 700H, SP =
FFFEH, SI = DI = 0000H and IF = 1. Consider the entire stack to be filled with 0000 before the execution of the code.

MOV AX,0ABCDH
MOV BX,1234H
MOV CX,5678H
MOV DX,9ABCH

CLC
STD

PUSHA

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution
PUSHA

This instruction pushes all the general-purpose registers onto the stack in the following order: AX, CX, DX, BX, SP, BP, DI, and SI. The value of
SP pushed is the value before the instruction is executed. It helps save state before an operation that could potentially change these registers.

Memory Locations Content Before Execution Content After Execution

0700:FFFE 0000 0000


After execution of the given instructions the
0700:FFFC 0000 ABCD new value of SP will be FFEEH.
0700:FFFA 0000 5678

0700:FFF8 0000 9ABC

0700:FFF6 0000 1234

0700:FFF4 0000 FFFE

0700:FFF2 0000 0000

0700:FFF0 0000 0000

0700:FFEE 0000 0000

10

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Exercise Problem 1

Q. Write a program in 8086 ALP to check if a string (having


length at least 2 bytes) stored in the memory is a palindrome or
not. If the string is a palindrome, store 1 in the AL register, and
store 0 in the AL register, if not.

11

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Algorithm for Exercise Problem 1
Note: A string is said to be a palindrome if it reads the same
from beginning to end as well as end to beginning. Therefore, a
string is a palindrome if it is equal to its reversed string. For
example, the string “malayalam” is a palindrome, while
“Malayalam” (when stored in memory) is not a palindrome.

1) Reverse the given string and store the reversed string in the
memory.
2) Check if the given string and the reversed string are equal.
12

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

You might also like