You are on page 1of 7

8086 program to sort an integer array in

ascending order
1. MOV SI, 500: set the value of SI to 500.
2. MOV CL, [SI]: load data from offset SI to register CL.
3. DEC CL: decrease value of register CL BY 1.
4. MOV SI, 500: set the value of SI to 500.
5. MOV CH, [SI]: load data from offset SI to register CH.
6. DEC CH: decrease value of register CH BY 1.
7. INC SI: increase value of SI BY 1.
8. MOV AL, [SI]: load value from offset SI to register AL.
9. INC SI: increase value of SI BY 1.
10. CMP AL, [SI]: compares value of register AL and [SI] (AL-[SI]).
11. JC 41C: jump to address 41C if carry generated.
12. XCHG AL, [SI]: exchange the contents of register AL and SI.
13. DEC SI: decrease value of SI by 1.
14. XCHG AL, [SI]: exchange the contents of register AL and SI.
15. INC SI: increase value of SI by 1.
16. DEC CH: decrease value of register CH by 1.
17. JNZ 40F: jump to address 40F if zero flat reset.
18. DEC CL: decrease value of register CL by 1.
19. JNZ 407: jump to address 407 if zero flat reset.
20. HLT: stop.

Method 2(easy)
mov si,500

mov cl,[500]

l:

mov al,[si]

inc si

cmp al,[si]

jnc 41c

xchg al,[si]

dec si
xchg al,[si]

inc si

dec cl

jnz l

hlt

8086 program to transfer a block of bytes by


using string instruction
1. MOV SI, 500: load the value 500 into offet SI.
2. MOV DI, 600: load the value 600 into offset DI.
3. MOV AX, 0000: load the value 0000 into AX register.
4. MOV DS, AX: load the value of AX register into DS (data segment).
5. MOV ES, AX: load the value of AX register into ES (extra segment).
6. MOV CL, [SI]: load the data of offset SI into CL register.
7. MOV CH, 00: load value 00 into CH register.
8. INC SI: increment the value of SI by one.
9. CLD: clears the directional flag i.e. DF=0.
10. REP: repeat until value of CX is not equal to zero and decrement the value of CX by one
at each step.
11. MOVSB: transfer the data from source memory location to destination memory location.
12. HLT: end.

1's Complement of a 16-bit Number -


8086 Program
8086 program to find the min value in a given
array
1. MOV SI, 500 assigns 500 to SI
2. MOV DI, 600 assigns 600 to DI
3. MOV CL, [SI] moves the content of [SI] to CL register
4. MOV CH, 00 assign 00 to CH register
5. INC SI increase the value SI by 1
6. MOV AL, [SI] moves the content of [SI] to AL register
7. DEC CX decrease the content of CX register by 1
8. INC SI increase the value SI by 1
9. MOV BL, [SI] moves the content of [SI] to BL register
10. CMP AL, BL subtract the value of BL register from AL and it modify flag registers
11. JC 0417 jump to 0417 address if carry flag is set
12. MOV AL, BL moves the content of BL register to AL register
13. LOOP 040E runs loop till CX not equal to Zero and decrease the value of CX by 1
14. MOV [DI], AL moves the content of AL to [DI]
15. HLT stops the execution of program

8086 program to determine largest number


in an array of n numbers
1. MOV SI, 500 : set the value of SI to 500
2. MOV CL, [SI] : load data from offset SI to register CL
3. MOV CH, 00 : set value of register CH to 00
4. INC SI : increase value of SI by 1.
5. MOV AL, [SI] : load value from offset SI to register AL
6. DEC CL : decrease value of register CL by 1
7. INC SI : increase value of SI by 1
8. CMP AL, [SI] : compares value of register AL and [SI] (AL-[SI])
9. JNC 413 : jump to address 413 if carry not generated
10. MOV AL, [SI] : transfer data at offset SI to register AL
11. INC SI : increase value of SI by 1
12. LOOP 40C : decrease value of register CX by 1 and jump to address 40D if value of
register CX is not zero
13. MOV [600], AL : store the value of register AL to offset 600
14. HLT : stop

8086 program to reverse a string


data segment

str1 db 'string_reverse\'

strlen1 dw $-str1

strrev db 20 dup('\') ; set 20 bytes of storage initialized as \

data ends

code segment

assume cs:code ds:data

Begin:

mov ax, data

mov ds,ax;

mov es,ax

mov cx, strlen1

add cx, -2

lea si,str1
lea di, strrev

add si, strlen1

add si,-2

L1:

mov al,[si]

mov [di],al

dec si

inc di

loop L1

mov al,[si]

mov [di],al

inc di

mov dl, '$'

mov [di], dl

print:

mov ah, 09h

lea dx,strrev

int 21h

exit:

mov ax,4c00h

int 21h

code ends

end Begin
Dfasdsadasdas
data segment
a dw 1,2,3,4,5,6,7,8,9,10
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov cl,10
lea bx,a
mov ax,00
l1: add ax, word ptr[bx]
add bx,02
dec cl
cmp cl,00
jnz l1
mov ah,4ch
int 21h
code ends
end start

You might also like