0% found this document useful (0 votes)
42 views

MP Tutorial

The document contains 10 problems related to assembly language programming. The problems cover topics like addressing modes, counting bits, finding smallest/largest values in arrays, sorting arrays, string manipulation, arithmetic operations, recursion, and binary search. Sample assembly code solutions are provided for each problem.

Uploaded by

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

MP Tutorial

The document contains 10 problems related to assembly language programming. The problems cover topics like addressing modes, counting bits, finding smallest/largest values in arrays, sorting arrays, string manipulation, arithmetic operations, recursion, and binary search. Sample assembly code solutions are provided for each problem.

Uploaded by

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

Microprocessor and

Microcontrollers(15CS44)
1. Assume that DS = 5000, SS = 4000, BX = 2100,
SI = 1486, DI = 8500, BP=7814, and AX =2512
All values are in hex. Show the exact physical
memory location where AX is stored in each of
the following.
(a) MOV[BX],AX (b) MOV[SI],AX
(c)MOV [BX][SI],AX (d) MOV[DI],AX
(e) MOV[BP],AX
a)50000+2100=52100
b)50000+1486=51486
c)50000+(2100+1486)=53586
d)50000+8500=58500
e)40000+7814=47814
2.Identify the addressing modes in the
following cases
a)MOV AX,BX
b)MOV BX,BLOCK
{MOV BX, OFFSET BLOCK}
c)MOV AX,[BX]
a)REGISTER
b)DIRECT
c)REGISTER INDIRECT
3.Write an ALP to count number of
1’s in a given 8-bit data
.MODEL SMALL
.STACK 60H
.DATA
D1 DB 97H
COUNT DB ?
.CODE
MOV AX,@DATA
MOV DS,AX
SUB BL,BL
MOV DL,8
MOV AL,D1
AGAIN:ROL AL,1
JNC NXT
INC BL
NXT: DEC DL
JNZ AGAIN
MOV COUNT,BL
MOV AH,4CH
INT 21H
4.Write an ALP to find the smallest in a
given array of 5 numbers(byte data).
• Data
Array db …..
Lowest db ?
.code
Start:MOV AX,@data
MOV DS,AX
MOV CX,5 ;set up loop counter
MOV BX,OFFSET array ;BX points to arraydata
MOV AL,0FFH ;AL holds lowest number found
so far
AGAIN: CMP AL,[BX] ;compare next num to lowest
JB NEXT ;jump if AL still lowest
MOV AL,[BX] ;else AL holds new lowest
NEXT: INC BX ;point to next num
LOOP AGAIN ;continue search
MOV LOWEST,AL ;store lowest num
MOV AH,4CH
INT 21H ;go back to dos
5.Write an ALP to bubble sort the following data
(23h, 11h, 85h, 0fah,06h)
.model small
.stack 20

.data
list db 23h, 11h, 85h, 0fah,06h
count equ 05h
.code
start: mov ax,@data
mov ds,ax
mov dx,count-1
again0: mov cx,dx
mov si,offset list

again1: mov al,[si]


cmp al,[si+1]
jl ahead1
xchg [si+1],al
xchg [si],al
ahead1:inc si
loop again1
dec dx
jnz again0
6.Write an ALP to convert lowercase in a given
string to uppercase. (hello Belagavi to HELLO
BELAGAVI)
MOV AX,@DATA
MOV DS,AX
MOV SI,OFFSET DATA1 ;SI points to original data
MOV BX,OFFSET DATA2 ;BX points to upper case data
MOV CX,14 ;CX is loop counter
BACK: MOV AL,[SI] ;get next character
CMP AL,61H ;if less than ‘a'
JB OVER ;then no need to convert
CMP AL,7aH ;if greater than ‘z'
JA OVER ;then no need to convert
AND AL,11011111B ;mask d5 to convert to upper
case
OVER: MOV [BX],AL ;store upper case character
INC SI ;increment pointer to original
INC BX ;increment pointer to upper case data
LOOP BACK ;continue looping if CX> 0
MOV AH,4CH
INT 21H ;go back to dos
END Start
7.Write an ALP to compute the sum of five
words of data.
.data
COUNT EQU 05
DATA DW 2300,4300,1200,3700,1234
SUM DW 2 DUP(?)
.code
……….
MOV CX,COUNT ;CX is the loop counter
MOV SI,OFFSET DATA ;SI is the data pointer
MOV AX,00 ;AX will hold the sum
MOV BX,AX ;BX will hold the carries
BACK: ADD AX,[SI] ;add the next word to AX
ADC BX,0 ;add carry to BX
INC SI ;increment data pointer twice
INC SI ; to point to next word
DEC CX ;decrement loop counter
JNZ BACK ;if not finished, continue adding
MOV SUM,AX ;store the sum
MOV SUM+2,BX ;store the carries
MOV AH,4CH
INT 21H ;go back to DOS
8.Write an ALP to add the numbers
548FB9963CE7H and 3FCD4FA23B8DH
.data
D1 dq 548FB9963CE7H
D2 dq 3FCD4FA23B8DH
D3 dq ?
.code

Clc; clear carry
Mov si ,offset d1
Mov di,offset d2
Mov bx,offset d3
Mov cx,4
Bk:mov ax,[si]
Adc ax,[si]
Mov [bx],ax
Inc si
Inc si
Inc di
Inc di
Inc bx
Inc bx
Loop back
Mov ah,4ch
Int 21h
9.Write an 8086 ALP to compute factorial of a
number using recursion.
.data
N1 db 5h
Ans db ?
.code

Mov BX,n1
Call factorial
Mov ans ,AX
factorial proc
cmp bx, 0001h
je back
push bx
dec bx
call factorial
pop bx
mul bx
ret
back: mov ax, 0001h
ret
factorial endp
10.Write an ALP to perform binary search for a
key 55h in an array (11h,22h,33h,44h,55h,66h),
display search successful/unsuccessful and
display the position of element.
.model small
.stack 20
.data
a db 11h,22h,33h,44h,55h,66h
count equ ($-a)
key db 55h
msg1 db 0dh,0ah,"search successful, key present at
position $"
msg2 db 0dh,0ah,"search unsuccessful$"
.code
start:mov ax,@data
mov ds,ax
mov bx,00
mov dx,count
mov cl,key
back: cmp dx,bx
jl fail
mov ax,bx
add ax,dx
shr ax,1
mov si,ax
cmp a[si],cl
jz success
cmp cl,a[si]
jnc big
dec ax
mov dx,ax
jmp back
big: inc ax
mov bx,ax
jmp back
success: mov bl,al
lea dx,msg1
mov ah,09h
int 21h
mov dl,bl
add dl,31h
mov ah,02h
int 21h
jmp ahead

fail: lea dx,msg2


mov ah,09h
int 21h
ahead: mov ah,4ch
int 21h

You might also like