You are on page 1of 12

Dilla University College of engineering and Technology

Department of electrical engineering

Communication Steam

Microprocessor individual assignment

Name : Ermias W/amanuel Worku

IDN : 6450/19

1. Convert the following pseudo code into 8086 ALP.


If AL <= BL Then
AL=0
Else
BL=0
ENDIF
MOV AX, [AL] ; Move the value of AL to AX
MOV BX, [BL] ; Move the value of BL to BX
CMP AX, BX ; Compare the values of AX and BX
JLE set_al_zero ; Jump to set_al_zero if AX <= BX
MOV BL, 0 ; Set BL to 0 if AX > BX
JMP end_if ; Jump to end_if
set_al_zero:
MOV AX, 0 ; Set AX to 0 if AX <= BX
end_if:
2. Check a number if it is even or odd by using logical operator/s.

MOV AX,
AND AX, 1 ; AND the number with 1
JZ even ; If the result is zero, the number is even
; Otherwise, the number is odd
odd:
; Code to execute if the number is odd
JMP end
even:
; Code to execute if the number is even
end:

3. Check if a number is negative or positive.


mov ax, number
test ax, ax
js negative
; number is positive
jmp done
negative:
; number is negative
done:
; continue execution

4. Write assembly language program that exchanges data at two different memory locations.
.MODEL SMALL
.STACK 100H

.DATA
location1 DW 1234h
location2 DW 5678h

.CODE
MOV AX, [location1] ; load value from location1 into AX
MOV BX, [location2] ; load value from location2 into BX
XCHG AX, BX ; exchange values of AX and BX
MOV [location1], AX ; store value of AX into location1
MOV [location2], BX ; store value of BX into location2

MOV AH, 4CH ; return control to DOS


INT 21H

END
.MODEL SMALL
.STACK 100H

.DATA
array DB 'S', 'd', 'Z', 'G', 'n', 'B', 'W', 'A', 'P', 'R'
capNum DB 0
notCapNum DB 0

.CODE
MOV CX, 10 ; loop 10 times
MOV SI, 0 ; initialize array index
READ_LOOP:
MOV AL, array[SI] ; read a character from array
CMP AL, 'A' ; check if character is between 'A' and 'Z'
JL ELSE ; jump to ELSE if character is less than 'A'
CMP AL, 'Z' ; check if character is between 'A' and 'Z'
JG ELSE ; jump to ELSE if character is greater than 'Z'
INC capNum ; increment capNum if character is between 'A' and 'Z'
JMP END_IF
ELSE:
INC notCapNum ; increment notCapNum if character is not between 'A' and 'Z'
END_IF:
INC SI ; increment array index
LOOP READ_LOOP ; repeat for 10 times

; print the results


MOV AH, 09H ; set output function
LEA DX, capMsg ; load capMsg address
INT 21H ; print capMsg
MOV DL, capNum ; load capNum
ADD DL, '0' ; convert capNum to ASCII
MOV AH, 02H ; set output function
INT 21H ; print capNum
MOV DL, ',' ; print comma
MOV AH, 02H ; set output function
INT 21H ; print comma
LEA DX, notCapMsg ; load notCapMsg address
INT 21H ; print notCapMsg
MOV DL, notCapNum ; load notCapNum
ADD DL, '0' ; convert notCapNum to ASCII
MOV AH, 02H ; set output function
INT 21H ; print notCapNum

MOV AH, 4CH ; return control to DOS


INT 21H

; messages
capMsg DB 'Number of capital letters: $'
notCapMsg DB 'Number of non-capital letters: $'

END
1. Write an assembly language program for searching smallest number in an array.

MOV CX, 10 ; Replace 10 with the size of your array


MOV SI, OFFSET array ; Replace array with the name of your array
MOV AX, [SI] ; Move the first element of the array to AX
loop start:
CMP AX, [SI] ; Compare AX with the current element of the array
JLE skip ; Jump to skip if AX <= current element
MOV AX, [SI] ; Move the current element to AX if it is smaller than AX
skip:
ADD SI, 2 ; Move to the next element of the array
LOOP loop_start ; Repeat until all elements have been compared
MOV BX, AX ; Move the smallest element to BX
2. Write an assembly language program that sorts the numbers in array in ascending order
; Sort an array of numbers in ascending order
; Input: array of numbers
; Output: sorted array of numbers

.model small
.stack 100h

.data
array db 5, 2, 8, 1, 3, 7, 9, 4, 6, 0
n equ 10

.code
main proc
mov ax, @data
mov ds, ax

; Sort the array in ascending order


mov cx, n
dec cx
outer_loop:
push cx
mov si, 0
inner_loop:
mov di, si
inc di
cmp di, cx
jg inner_loop_done
mov al, array[si]
mov bl, array[di]
cmp al, bl
jle inner_loop_continue
mov array[si], bl
mov array[di], al
inner_loop_continue:
inc si
jmp inner_loop
inner_loop_done:
pop cx
loop outer_loop

; Display the sorted array


mov ah, 09h
lea dx, array
int 21h
mov ah, 4ch
int 21h
main endp
end main
3. Find sum of cubes of first n natural numbers.

.model small
.stack 100h

.data
n dw 5
sum dw ?

.code
main proc
mov ax, @data
mov ds, ax

; Calculate the sum of cubes of the first n natural numbers


mov cx, n
mov bx, 0
mov sum, 0
loop_start:
cmp cx, 0
je loop_end
mov ax, cx
mul cx
mul cx
add sum, ax
dec cx
jmp loop_start
loop_end:

; Display the sum of cubes of the first n natural numbers


mov ah, 09h
mov dx, offset sum
int 21h

mov ah, 4ch


int 21h
main endp
end main
; Initialize count to 0
MOV CX, 0

; Initialize oddNum to 0
MOV BX, 0

; Initialize evenNum to 0
MOV AX, 0

WHILE_LOOP:
; Check if count < 20
CMP CX, 20
JGE END_WHILE

; Check if count is odd


MOV DX, 0
MOV AX, CX
DIV TWO
CMP DX, 0
JNE ODD_NUM
EVEN

You might also like