0% found this document useful (0 votes)
18 views8 pages

MIC Unit 4

The document contains a series of assembly language programs for various operations such as addition, subtraction, multiplication, division, and sorting of numbers, primarily focusing on 8-bit and 16-bit numbers. It includes possible corrections and enhancements for each program, such as changing data types and using specific instructions. Additionally, the document outlines procedures for counting bits, transferring data blocks, and finding the largest number in an array.

Uploaded by

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

MIC Unit 4

The document contains a series of assembly language programs for various operations such as addition, subtraction, multiplication, division, and sorting of numbers, primarily focusing on 8-bit and 16-bit numbers. It includes possible corrections and enhancements for each program, such as changing data types and using specific instructions. Additionally, the document outlines procedures for counting bits, transferring data blocks, and finding the largest number in an array.

Uploaded by

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

Program: Computer Engineering

Microprocessors (22415)

4. Assembly Language Programming .model small


1.ALP to add two 8-bit numbers.
.data
Ans:
A db 11h
.model small
B db 22h
.data
Ends
A db 11h
.code
B db 22h
Mov ax,@data
Ends
Mov ds,ax
.code
Mov al,a
Mov ax,@data
Mov bl,b
Mov ds,ax
Subal,bl
Mov al,a
Int 03h
Mov bl,b
Ends
Add al,bl
End
Int 03h
Possible Corrections
Ends changes
Subtraction Change Data: 11h to 1111h
End
Two 16-Bit 22 to 2222h
Possible Corrections number Registers: Al to AX
changes Bl to BX
Addition Two Change Data: 11h to 1111h
16-Bit 22 to 2222h With Borrow Use SBB instruction
number Registers: Al to AX For BCD After subtraction use DAS
Bl to BX number instruction

With carry Use ADC instruction


3. ALP to multiply two 8-bit numbers.
For BCD After addition use DAA
number instruction Ans:

.model small
2. ALP to Subtract two 8-bit numbers.
.data
Ans:
Page 1 of 8
Program: Computer Engineering
Microprocessors (22415)

A db 02h Div bl
B db 02h Int 03h
Ends Ends
.code End
Mov ax,@data
Mov ds,ax
Mov al,a
Mov bl,b
Possible Corrections
Mul bl
changes
Int 03h
Multiplication Change Data: 02h to 1111h
Ends Two 16-Bit 02 to 2222h
End number Registers: Al to AX
Possible Corrections Bl to BX
changes
Multiplication Change Data: 02h to 1111h Singed
Use IDIV instruction
Two 16-Bit 02 to 2222h Numbers
number Registers: Al to AX For BCD After Division use AAD
Bl to BX number instruction

Singed 5. ALP to find largest number in array.


Use IMUL instruction
Numbers
For BCD After Multiplication use AAM Ans:
number instruction .model small

.data
4. ALP to divide two numbers.
Array db 02h,04h,06h,01h,05h
Ans:
Ends
.model small
.code
.data
A dw 2222h Start:Mov ax,@data
B db 02h Mov ds,ax
Ends
.code Mov cl,04h
Mov ax,@data Lea si,array
Mov ds,ax
Mov ax,a Mov al,[si]
Mov bl,b
Page 2 of 8
Program: Computer Engineering
Microprocessors (22415)

Up :inc si MOV CL,09H

Cmp al,[si] STEP2: MOV AL,[SI

Jnc next CMP AL,[SI+1]

Mov al,[si] JC DOWN

Next :dec cl XCHG AL, [SI+1]

Jnz up XCHG AL,[SI]

Int 03h DOWN: ADD SI, 01LOOP STEP2

Ends DEC BL

End start JNZ STEP1

Possible Corrections MOV AH,4CH


changes
INT 21H
For 16-Bit Change Data: 8-bit with 16-
number bit
ENDS
For Smallest
Use JC instruction
Number END START

Possible Corrections
6. Write an ALP for 8086 to sort the array changes
in ascending order. For 16-Bit Change Data: 8-bit with 16-
number bit
Ans:
For
.model small Descending Use JNC instruction
Number
.DATA

ARRAY DB 7. Write an ALP to count the number of „1‟


06H,09H,22H,02H,07H,10H,11H,12H,13H,14H in a 16 bit number.
ENDS
Assume the number to be stored in BX
.CODE register. Store the result in CX register.
START: MOV AX,DATA Ans:
MOV DS,AX .MODEL SMALL
MOV BL,0AH .DATA
STEP1: MOV SI, OFFSET ARRAY NUM DW 0008H
Page 3 of 8
Program: Computer Engineering
Microprocessors (22415)

ONES DB 00H Without string Instruction


.CODE .model small
START: .data
MOV AX,@DATA Block1 db 01h,02h,03h,04h,05h
MOV DS,AX Block2 db 00h,00h,00h,00h,00h
MOV CX, 10H ; initialize rotation counter by Ends
16
MOV BX, NUM ;load number in BX
.code
UP: ROR BX, 1 ; rotate number by 1 bit right
JNC DN ; if bit not equal to 1 then go Start:Mov
to DN ax,@data
INC ONES ; else increment ones by one
DN: LOOP UP Mov ds,ax
;decrement rotation counter by 1 and if not zero
then go to up Mov si,offset block1

MOV CX, ONES ;move result in cx register. Mov di, offset block2

MOV AH, 4CH Mov cx,00005


INT 21H
Back: Mov al,[si]

Mov [di],al
ENDS
Inc si
END ; end of program.
Inc di
Possible Corrections
changes Loop back
Find number
Change Instruction: JNC to JC Int 03h,
of Zeros
Find Positive Ends
Change Instruction: ROR to
number or
ROL End start
Negative
number

With string instruction


8. To transfer block of data from one block
to another model small

1)With string instruction .data

2)Without string Instruction Block1 db 01h,02h,03h,04h,05h

Block2 db 00h,00h,00h,00h,00h
Page 4 of 8
Program: Computer Engineering
Microprocessors (22415)

Ends Mov si,offset block1

.code Mov di, offset block2

Start:Mov ax,@data Mov cx,00005

Mov ds,ax Back: Mov al,[si]

Mov si,offset block1 Mov bl,[di]

Mov di, offset block2 Mov [di],al

Mov cx,00005 Mov [si],bl

Rep movs b Inc si

Int o3 h, Inc di

Ends Loop back

end Int 03h,

Mov cx,00005 Ends

Possible Corrections End start


changes
10. Write an assembly language program
For 16-Bit Change Data: 8-bit with 16-
to count even number in an array
number bit
of five 16 bit number.
Instruction Use MOVS W
DATA SEGMENT
NUM DW 1200h,2345h,4567h,7864h,2587h
9. Write a program for Block exchange
COUNT DB?
without using string instruction DATA ENDS
model small CODE SEGMENT
ASSUME CS:CODE, DS:DATA
.data START: MOV AX,DATA
Block1 db 01h,02h,03h,04h,05h MOV DS,AX
MOV CX,14H
Block2 db 11h,22h,33h,44h,55h MOV SI, OFFSET NUM
NEXT: MOV AL, [SI]
Ends
INC SI
.code MOV AH,[SI]
ROL AX,01
Start:Mov ax,@data JNC DOWN
Mov ds,ax INC COUNT
Page 5 of 8
Program: Computer Engineering
Microprocessors (22415)

DOWN: INC SI EXIT: MOV LEN,CL


LOOP NEXT MOV AH,4CH
MOV AX, 4C00H INT 21H
CODE ENDS
INT 21H
CODE ENDS 12.Write an ALP to reverse a string. Also
draw flowchart for same.
Possible Corrections
changes Program:
For 8-Bit Change Data: 16-bit with 8- DATA SEGMENT
number bit STRB DB 'GOOD MORNING$'
For odd Use instruction JC REV DB 0FH DUP(?)
number DATA ENDS
To count CODE SEGMENT
Positive Use ROR AX,01 AND JNC START:ASSUME CS:CODE,DS:DATA
number MOV DX,DATA
To count MOV DS,DX
Negative Use ROR AX,01 AND JC LEA SI,STRB
Number MOV CL,0FH
LEA DI,REV
ADD DI,0FH

UP:MOV AL,[SI]
11.Write an ALP to find length of string MOV [DI],AL
Data Segment INC SI
STRG DB 'GOOD MORNING$' DEC DI
LEN DB ? LOOP UP
DATA ENDS MOV AH,4CH
CODE SEGMENT INT 21H
START: CODE ENDS
ASSUME CS: CODE, DS : DATA END START
MOV DX, DATA
MOV DS,DX
LEA SI, STRG
MOV CL,00H
MOV AL,'$'
NEXT: CMP AL,[SI]
JZ EXIT
ADD CL,01H
INC SI
Page 6 of 8
Program: Computer Engineering
Microprocessors (22415)

MOV SI, OFFSET NUM1


UP: CALL SUM
INC SI
LOOP UP
MOV AH,4CH
INT 21H
SUM PROC; Procedure to add two 8 bit
numbers
MOV AL,[SI]
ADD RESULT, AL
JNC NEXT
INC CARRY
NEXT: RET
SUM ENDP
CODE ENDS
END STAR

14.Write an assembly language program to


solve p= x2+y2 using Macro.(x
and y are 8 bit numbers
.MODEL SMALL
PROG MACRO a,b
MOV al,a
MUL al
MOV bl,al
MOV al,b
MUL al
ADD al,bl
13. Write an ALP for addition of series of 8-
ENDM
bit number using procedure .DATA
DATA SEGMENT x DB 02H
NUM1 DB 10H,20H,30H,40H,50H y DB 03H
RESULT DB 0H
CARRY DB 0H

DATA ENDS p DB DUP()


CODE SEGMENT .CODE
ASSUME CS:CODE, DS:DATA START:
START: MOV DX,DATA MOV ax,data
MOV DS, DX MOV ds,ax
MOV CL,05H PROG x, y
Page 7 of 8
Program: Computer Engineering
Microprocessors (22415)

MOV p,al Mov al ,[bl]


MOV ah,4Ch Skip: inc bl
Int 21H Loop again
END Endm
.data
15. Write an assembly language program
Nums db 44h,55h,66h,77h,88h
to mask the lower nibble of 8-bit
Count db 05h
number
Largest db?
.model small .code
.data Start: mov ax, @data
a dw 0012H Mov ds,ax
.code Mov al,00h
mov ax, @data ; Initialize data section Mov cl, count
mov ds, ax Mov bl,nums
mov ax, a ; Load number1 in ax LrgMac
and al, 0f0h ; mask lower nibble. Result in al Mov largest , al
mov ch, 02h ; Count of digits to be displayed Ends
mov cl, 04h ; Count to roll by 4 bits End
mov bh, al ; Result in reg bh
up: rol bh, cl ; roll bl so that msb comes to lsb
mov dl, bh ; load dl with data to be displayed
and dl, 0fH ; get only lsb
cmp dl, 09 ; check if digit is 0-9 or letter A-F
jbe tr
add dl, 07 ; if letter add 37H else only add 30H
tr: add dl, 30H
mov ah, 02 ; Function 2 under INT 21H
(Display character)
int 21H
dec ch ; Decrement Count
jnz up
mov ah, 4ch
int 21h
end
16. Write an assembly language program
to find largest number among
block of data using macro.
LrgMac MACRO
Again: cmp al,[bl]
Jnc skip
Page 8 of 8

You might also like