Professional Documents
Culture Documents
Da1 Theory DLM
Da1 Theory DLM
MICROPROCESSOR THEORY
SWE-1003
DA-1
SUBMITTED BY:
SUMIT PAUDEL
22MIS0401
Write an 8086 assembly language program for the following
1.Program to get the count of even numbers from the list of n numbers.
; Program to count even numbers in a list of n numbers
ORG 100h ; Set the origin to 100h for COM file
section .data
n dw 5 ; Number of elements in the list
numbers db 1, 2, 3, 4, 5 ; List of numbers
section .text
global _start
_start:
count_even:
mov al, [si] ; Load the current number into AL
and al, 1 ; Check if it's even (by checking the LSB)
jz is_even ; If the result of AND operation is 0, it's even
not_even:
inc si ; Move to the next number in the array
loop count_even ; Continue the loop for the next element
jmp done ; Exit the loop
is_even:
inc ax ; Increment the count of even numbers
inc si ; Move to the next number in the array
loop count_even ; Continue the loop for the next element
done:
; At this point, AX contains the count of even numbers
; You can use it for further processing or display
; (e.g., printing the count)
section .data
n db 10 ; Number of Fibonacci numbers to generate
section .bss
fib_numbers resw 10 ; Array to store Fibonacci numbers
section .text
global _start
_start:
mov cx, [n] ; Load the number of Fibonacci numbers to generate
mov bx, 0 ; Initialize loop counter
mov word [fib_numbers], 0 ; Initialize the first Fibonacci number
mov word [fib_numbers + 2], 1 ; Initialize the second Fibonacci number
generate_fibonacci:
; Calculate the next Fibonacci number
mov ax, [fib_numbers + bx]
add ax, [fib_numbers + bx + 2]
mov [fib_numbers + bx + 4], ax ; Store the result
loop generate_fibonacci ; Repeat the loop until all numbers are generated
print_fibonacci:
mov ax, [fib_numbers + si]
call print_number
add si, 2
loop print_fibonacci
print_number:
; Print the number in AX
push ax
mov cx, 0
mov bx, 10
reverse_loop:
xor dx, dx
div bx
add dl, '0'
push dx
inc cx
test ax, ax
jnz reverse_loop
print_loop:
pop dx
mov ah, 2
int 21h
loop print_loop
; Print a newline
mov dl, 10
int 21h
pop ax
ret
section .data
array db 7, 1, 3, 9, 2, 5, 8, 4, 6, 0 ; Array to be sorted
n db 10 ; Number of elements in the array
section .text
global _start
_start:
sort_loop:
xor bh, bh ; Reset flag to 0 (no swaps yet)
mov ch, cl ; Set the inner loop counter to n
inner_loop:
mov al, [si] ; Load the current element
mov dl, [si + 1] ; Load the next element
cmp al, dl
jle no_swap ; If al <= dl, no swap needed
no_swap:
inc si
loop inner_loop
done:
; The sorted array is now in memory, you can print or use it as needed
section .text
global _start
_start:
5. Program to get the count of odd numbers from the list of n numbers
ORG 100h ; Set the origin to 100h for COM file
section .data
n db 5 ; Number of elements in the list
numbers db 1, 2, 3, 4, 5, 0 ; List of numbers, terminated with 0
section .text
global _start
_start:
count_odd:
mov al, [si] ; Load the current number into AL
cmp al, 0 ; Check if it's the end of the list
je done ; If it's the end of the list, exit the loop
not_odd:
inc si ; Move to the next number in the array
loop count_odd ; Continue the loop for the next element
jmp done
is_odd:
inc ax ; Increment the count of odd numbers
done:
; At this point, AX contains the count of odd numbers
; You can use it for further processing or display
1. Design a Half adder and Full adder / Half Subtractor and Full Subtractor
HALF ADDER
FULL ADDER
Half Subtractor
Full Subtractor
2. Design a BCD to Excess-3 code converter using logic gates.