MIC Programs
MIC Programs
.model small
.data
.code
mov ax, @data
mov ds, ax
.model small
.data
.code
mov ax, @data
mov ds, ax
mov si, 4000H
mov cx, 10
mov ax, 0
sum_loop:
add ax, [si]
inc si
loop sum_loop
mov [400Ah], ax
mov ah, 4Ch
int 21H
end
Q.8 Program in 8086 to to find smallest number in an array of 10
numbers stored from memory location 0101h
OR
Q. 12 program in 8086 to to find smallest number in an array of 10
numbers stored from memory location 1000 h
.model small
.data
.code
mov ax, @data
mov ds, ax
mov si, 0101H ; OR 1000H
mov cx, 10
mov ax, [si]
inc si
dec cx
find_smallest:
cmp ax, [si]
jle next_num ; If AX <= [SI], go to next number
mov ax, [si]
next_num:
inc si
loop find_smallest
mov [0115H], ax
mov ah, 4Ch ; Exit program
int 21H
end
Q. 13 program in 8086 to to find Largest number in an array of 10
numbers stored from memory location 1000 h
.model small
.data
.code
mov ax, @data
mov ds, ax
mov si, 1000H
mov cx, 10
mov ax, [si]
inc si
dec cx
find_largest:
cmp ax, [si]
memory [SI]
jge next_num ; If AX >= [SI], go to next number
mov ax, [si]
next_num:
inc si
loop find_largest
mov [1010H], ax
mov ah, 4Ch ; Exit program
int 21H
end
Q.9 program in 8086 to to sort number in an array of 5 numbers in
ascending order which is stored from 2000H memory location
.model small
.data
.code
mov ax, @data
mov ds, ax
mov si, 2000H
mov cx, 5
mov bx, cx
outer_loop:
dec bx
mov si, 2000H
mov di, si
mov dx, bx
inner_loop:
mov ax, [si]
cmp ax, [di]
jbe no_swap ; If AX <= [DI], no need to swap
xchg ax, [di]
mov [si], ax
no_swap:
inc si
inc di
loop inner_loop
mov cx, bx
loop outer_loop
inc si
inc di
loop copy_loop
.model small
.stack 100h
.data
array db 2, -3, 5, -8, 7, -1, 4, -2
size db $ - array ; Size of the array
.code
start:
; Initialize data segment
mov ax, @data
mov ds, ax
separate_numbers:
mov al, [si] ; Load the current array element into AL
cmp al, 0 ; Compare with 0
jge store_positive ; If AL >= 0, jump to store positive number
store_negative:
mov [bx], al ; Store the negative number in the negative array
inc bx ; Move the pointer to the next negative position
inc neg_count ; Increment negative count
jmp next_element
store_positive:
mov [di], al ; Store the positive number in the positive array
inc di ; Move the pointer to the next positive position
inc pos_count ; Increment positive count
next_element:
inc si ; Move to the next element in the array
loop separate_numbers ; Repeat until the whole array is processed
end start