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

MP Codes

The document contains multiple assembly language programs for the 8086 architecture, demonstrating operations such as 16-bit and 8-bit addition and subtraction, block data transfer, and sorting algorithms (both ascending and descending). It also includes programs for counting even and odd bits in a number. Each program is structured with data and code segments, and uses DOS interrupts for program termination.

Uploaded by

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

MP Codes

The document contains multiple assembly language programs for the 8086 architecture, demonstrating operations such as 16-bit and 8-bit addition and subtraction, block data transfer, and sorting algorithms (both ascending and descending). It also includes programs for counting even and odd bits in a number. Each program is structured with data and code segments, and uses DOS interrupts for program termination.

Uploaded by

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

16 bit add

.8086

.MODEL SMALL

.DATA

num1 DW 1234H

num2 DW 1234H

result DW ?

carry DB 0

.CODE

START:

MOV AX, @DATA

MOV DS, AX

MOV AX, num1

MOV BX, num2

ADD AX, BX ; AX = num1 + num2

MOV CL, 00H ; Initialize carry flag as 0

JNC LABEL1 ; If no carry, jump

MOV CL, 01H ; Set carry if it occurs

LABEL1:

MOV result, AX

MOV carry, CL

MOV AH, 4CH

INT 21H

END START

16 bit subtract

.8086
.MODEL SMALL

.DATA

num1 DW 1234H

num2 DW 0ABC2H

result DW ? ; Store result

.CODE

START:

MOV AX, @DATA

MOV DS, AX

MOV AX, num1 ; Load first number (minuend)

MOV BX, num2 ; Load second number (subtrahend)

SUB AX, BX ; AX = AX - BX

MOV result, AX ; Store the result

MOV AH, 4CH

INT 21H

END START

8 bit add

.8086

.MODEL SMALL

.DATA

num1 DB 22H

num2 DB 33H

result DB ?

.CODE

START:

MOV AX, @DATA

MOV DS, AX

MOV AL, num1


MOV BL, num2

ADD AL, BL

MOV result, AL

MOV AH, 4CH

INT 21H

END START

8 bit subtract

.8086

.MODEL SMALL

.DATA

num1 DB 33H

num2 DB 22H

result DB ?

.CODE

START:

MOV AX, @DATA

MOV DS, AX

MOV AL, num1

MOV BL, num2

SUB AL, BL

MOV result, AL

MOV AH, 4CH

INT 21H

END START

Block transfer

.8086

.model small
.data

a db 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH

b db 10

.code

start: mov ax,@data

mov ds,ax

mov es,ax

lea si,a

lea di,b

mov cx, 000AH

rep movsb

mov ah,4ch

int 21h

end start

Even odd (10 nos)

.8086

.model small

.data

a db 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH

.code

start: mov ax,@data

mov ds,ax

mov es,ax

mov bx,0000H

lea si,a

mov cx, 000AH


check:mov al,[si]

ror al,01H

jc odd

inc bl

jmp next

odd: inc bh

loop check

mov ah,4ch

int 21h

end start

Descending

.8086

.MODEL SMALL

.DATA

Dblock DB 15H, 19H, 12H, 17H, 14H

.CODE

START:

MOV AX, @DATA

MOV DS, AX

LEA SI, Dblock

MOV CL, 04H ; 4 passes for 5 elements

OUTER_LOOP:

MOV BL, CL

MOV DI, SI

INNER_LOOP:

MOV AL, [DI]

MOV DL, [DI+1]


CMP AL, DL

JAE SKIP ; If AL >= DL, no swap

XCHG AL, DL

MOV [DI], AL

MOV [DI+1], DL

SKIP:

INC DI

DEC BL

JNZ INNER_LOOP

DEC CL

JNZ OUTER_LOOP

MOV AH, 4CH

INT 21H

END START

Ascending

.MODEL SMALL

.DATA

Dblock DB 15h, 19h, 12h, 17h, 14h ; Array to be sorted

.CODE

Start:

MOV AX, @DATA

MOV DS, AX

LEA SI, Dblock

MOV CL, 04h ; 4 passes for 5 elements


Vp:

MOV BL, CL

MOV DI, SI

MOV AL, [SI]

INC SI

CMP AL, [SI]

JBE Down ; Change JA to JBE for ascending order

XCHG AL, [SI]

Down:

DEC BL

JNC Vp

MOV SI, DI ; Reset SI for next pass

DEC CL ; Reduce pass count

JNZ Vp ; Repeat if passes remain

MOV AH, 4CH ; Exit program

INT 21H

END Start

Even odd (8 bit)

.MODEL SMALL

.DATA

even_count DB 0

odd_count DB 0

.CODE

START:

MOV AX, @DATA


MOV DS, AX

MOV AL, 11010110B ; Example 8-bit number (change as needed)

MOV CX, 08H ; Loop 8 times for 8 bits

XOR BL, BL ; BL = even count (initialize to 0)

XOR BH, BH ; BH = odd count (initialize to 0)

CHECK:

ROR AL, 1 ; Rotate right, LSB goes to Carry flag

JNC EVEN ; If CF = 0, it's an even bit

INC BH ; Odd count increment

JMP NEXT

EVEN:

INC BL ; Even count increment

NEXT:

LOOP CHECK ; Repeat 8 times

MOV AH, 4CH ; Exit program

INT 21H

END START

You might also like