micrplab
micrplab
School of informatics
Department of computer science
Microprocessor and assembly language
Group Lab_ Assignment
Section 1
Name ID number
1. Gemechis Gurmessa……………………………….ugr/69416/14
2. Kalkidan Aly…………………………………………...ugr/69737/14
3. Khalid Abdiwahid Aw Ahmed ………………...ugr/75789/14
4. Lema Feyisa …………………………………………….ugr/69856/14
5. Bazawit Degefu………………………………………..ugr/68728/14
i
Microprocessor and assembly language
1. Write a program to read one of the hexadecimal digits A-F, and display it in a
decimal.
.model small
.stack 100h
.data
.code
main proc
mov ds, ax
int 21h
int 21h
1
Microprocessor and assembly language
mov hexDigit, al
mov decValue, al
int 21h
int 21h
int 21h
main endp
2
Microprocessor and assembly language
end main
2. Write emu 8086 program which display even or odd via keyboard.
.model small
.stack 100h
.data
.code
main proc
mov ds, ax
int 21h
int 21h
3
Microprocessor and assembly language
sub al, '0' ; Convert ASCII to numerical value
mov digit, al
cmp al, 0
je Even
jmp DisplayMessage
Even:
DisplayMessage:
int 21h
int 21h
main endp
end main
4
Microprocessor and assembly language
3. Write a program to find the greatest common divisor (GCD) of two integers X and Y.
.model small
.stack 100h
.data
X dw 0
Y dw 0
gcd dw 0
.code
main proc
mov ds, ax
int 21h
call ReadInteger
mov X, ax
5
Microprocessor and assembly language
; Get second integer from user
int 21h
call ReadInteger
mov Y, ax
mov ax, X
mov bx, Y
call ComputeGCD
mov gcd, ax
int 21h
call PrintInteger
int 21h
6
Microprocessor and assembly language
; Subroutine to read an integer from the user
ReadInteger proc
int 21h
ReadLoop:
je DoneRead
mov bx, 10
mul bx ; Multiply AX by 10
jmp ReadLoop
DoneRead:
ret
ReadInteger endp
7
Microprocessor and assembly language
ComputeGCD proc
cmp bx, 0
je EndGCD
GCDLoop:
div bx ; AX = AX / BX, DX = AX % BX
mov ax, bx ; AX = BX
cmp bx, 0
jne GCDLoop
EndGCD:
ret
ComputeGCD endp
PrintInteger proc
ConvertLoop:
mov bx, 10
div bx ; AX = AX / 10, DX = AX % 10
dec di
8
Microprocessor and assembly language
mov [di], dl
cmp ax, 0
jne ConvertLoop
int 21h
ret
PrintInteger endp
main endp
end main
4. Write emu 8086 program which display increment of the days in one month via keyboard.
.model small
.stack 100h
.data
9
Microprocessor and assembly language
.code
main proc
mov ds, ax
InputLoop:
int 21h
call ReadInteger
cmp ax, 1
jl InvalidInput
cmp ax, 31
jg InvalidInput
mov cx, ax
10
Microprocessor and assembly language
lea dx, days_msg
int 21h
mov bx, 0
mov si, cx
IncrementLoop:
mov al, bl
inc al
mov days[bx], al
inc bx
loop IncrementLoop
mov cx, si
mov bx, 0
DisplayDays:
int 21h
int 21h
inc bx
11
Microprocessor and assembly language
loop DisplayDays
int 21h
InvalidInput:
int 21h
jmp InputLoop
ReadInteger proc
int 21h
ReadLoop:
12
Microprocessor and assembly language
cmp cl, 0 ; Check for end of string
je DoneRead
mov bx, 10
mul bx ; Multiply AX by 10
jmp ReadLoop
DoneRead:
ret
ReadInteger endp
main endp
end main
5. Write emu 8086 program which display one of the student score (0-100) and pass or
fail of that scored value via keyboard.
.model small
.stack 100h
.data
pass_msg db 'Pass$'
fail_msg db 'Fail$'
13
Microprocessor and assembly language
input_buffer db 4, 0, 0, 0, 0 ; Buffer to store input
.code
main proc
mov ds, ax
InputLoop:
int 21h
call ReadInteger
cmp ax, 0
jl InvalidInput
jg InvalidInput
cmp ax, 50
14
Microprocessor and assembly language
jl Fail
jmp DisplayMessage
Fail:
DisplayMessage:
int 21h
int 21h
InvalidInput:
int 21h
jmp InputLoop
ReadInteger proc
15
Microprocessor and assembly language
mov ah, 0Ah
int 21h
ReadLoop:
je DoneRead
mov bx, 10
mul bx ; Multiply AX by 10
jmp ReadLoop
DoneRead:
ret
ReadInteger endp
main endp
end main
16