Professional Documents
Culture Documents
Lab Assessment - 2
Lab Assessment - 2
1. Write an ALP using 8086 instructions to generate and add the first 10 even
numbers and save the numbers and result in memory location : Num and Sum.
Ans :
Code :
Output:
2. Write an 8086 alp to search for a given 16 bit value using binary search in an
array of 16 bit numbers, which are in sorted. Display the status in any one of the
registers (found or not). If the element is found the position of the element in
the array is to be displayed.
Ans:
Code :
.model small
.stack 100h
.data
array dw 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 ; Sorted array of 16-bit numbers
array_len dw 10
target dw 13
found dw 0
position dw 0
.code
main proc
mov ax, @data
mov ds, ax
binary_search:
cmp si, di
jg not_found
search_left:
mov di, bx
dec di
jmp binary_search
found_element:
mov ax, 1
mov found, ax
mov position, bx
jmp display_status
not_found:
mov ax, 0
mov found, ax
display_status:
mov bx, position
; Program end
mov ax, 4C00h
int 21h
main endp
end main
Output :