0% found this document useful (0 votes)
25 views17 pages

micrplab

The document contains a lab assignment for a Microprocessor and Assembly Language course at Wolaita Sodo University, detailing several programming tasks. These tasks include writing programs to convert hexadecimal digits to decimal, determine if a number is even or odd, compute the greatest common divisor (GCD), increment days in a month, and evaluate student scores. Each task is accompanied by sample code written in assembly language using the emu 8086 emulator.

Uploaded by

Gemechis Gurmesa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views17 pages

micrplab

The document contains a lab assignment for a Microprocessor and Assembly Language course at Wolaita Sodo University, detailing several programming tasks. These tasks include writing programs to convert hexadecimal digits to decimal, determine if a number is even or odd, compute the greatest common divisor (GCD), increment days in a month, and evaluate student scores. Each task is accompanied by sample code written in assembly language using the emu 8086 emulator.

Uploaded by

Gemechis Gurmesa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Microprocessor and assembly language

Wolaita Sodo university

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

Submission date: 14/10/2016 EC

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

hexDigit db 0 ; To store the hexadecimal digit input

decValue db 0 ; To store the decimal equivalent of the hex digit

msg1 db 'Enter a hexadecimal digit (A-F): $'

msg2 db 'The decimal value is: $'

result db 3 dup('$') ; To store the result string

.code

main proc

; Initialize data segment

mov ax, @data

mov ds, ax

; Display the input message

mov ah, 09h

lea dx, msg1

int 21h

; Read a single character from the user

mov ah, 01h

int 21h

1
Microprocessor and assembly language
mov hexDigit, al

sub al, 'A' ; 'A' is 41h in ASCII, subtract to get 0-5

add al, 10 ; Add 10 to convert A-F to 10-15

mov decValue, al

; Display the output message

mov ah, 09h

lea dx, msg2

int 21h

; Convert decimal value to string

; This is a simple way since the values are between 10 and 15

mov al, decValue

add al, 30h ; Convert to ASCII

mov result, al ; Store in result

; Display the result

lea dx, result

mov ah, 09h

int 21h

; Exit the program

mov ah, 4Ch

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

digit db 0 ; To store the digit input

msg1 db 'Enter a decimal digit (0-9): $'

even_msg db 'The digit is even.$'

odd_msg db 'The digit is odd.$'

.code

main proc

; Initialize data segment

mov ax, @data

mov ds, ax

; Display the input message

mov ah, 09h

lea dx, msg1

int 21h

; Read a single character from the user

mov ah, 01h

int 21h
3
Microprocessor and assembly language
sub al, '0' ; Convert ASCII to numerical value

mov digit, al

; Check if the digit is even or odd

mov ah, 0 ; Clear AH to use AX for division

mov al, digit ; Move digit into AL

and al, 01h ; Check the least significant bit

; Display the result

cmp al, 0

je Even

lea dx, odd_msg

jmp DisplayMessage

Even:

lea dx, even_msg

DisplayMessage:

mov ah, 09h

int 21h

; Exit the program

mov ah, 4Ch

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

prompt1 db 'Enter the first integer: $'

prompt2 db 'Enter the second integer: $'

result_msg db 'The GCD is: $'

X dw 0

Y dw 0

gcd dw 0

input_buffer db 6,0,0,0,0,0 ; Buffer to store input integers

.code

main proc

; Initialize data segment

mov ax, @data

mov ds, ax

; Get first integer from user

lea dx, prompt1

mov ah, 09h

int 21h

call ReadInteger

mov X, ax

5
Microprocessor and assembly language
; Get second integer from user

lea dx, prompt2

mov ah, 09h

int 21h

call ReadInteger

mov Y, ax

; Compute GCD using Euclidean algorithm

mov ax, X

mov bx, Y

call ComputeGCD

mov gcd, ax

; Display result message

lea dx, result_msg

mov ah, 09h

int 21h

; Convert GCD to ASCII and display

call PrintInteger

; Exit the program

mov ah, 4Ch

int 21h

6
Microprocessor and assembly language
; Subroutine to read an integer from the user

ReadInteger proc

lea dx, input_buffer

mov ah, 0Ah

int 21h

; Convert string to integer

lea si, input_buffer + 2 ; Offset to the first digit

xor ax, ax ; Clear AX

xor cx, cx ; Clear CX

ReadLoop:

mov cl, [si] ; Get character

cmp cl, 0 ; Check for end of string

je DoneRead

sub cl, '0' ; Convert ASCII to digit

mov bx, 10

mul bx ; Multiply AX by 10

add ax, cx ; Add digit to AX

inc si ; Move to the next character

jmp ReadLoop

DoneRead:

ret

ReadInteger endp

; Subroutine to compute GCD using Euclidean algorithm

7
Microprocessor and assembly language
ComputeGCD proc

cmp bx, 0

je EndGCD

GCDLoop:

xor dx, dx ; Clear DX before DIV

div bx ; AX = AX / BX, DX = AX % BX

mov ax, bx ; AX = BX

mov bx, dx ; BX = remainder

cmp bx, 0

jne GCDLoop

EndGCD:

ret

ComputeGCD endp

; Subroutine to print an integer

PrintInteger proc

; Convert integer to string (AX contains the integer)

lea di, input_buffer + 2 ; Buffer to store the string

mov cx, 0 ; Clear CX (digit count)

ConvertLoop:

xor dx, dx ; Clear DX

mov bx, 10

div bx ; AX = AX / 10, DX = AX % 10

add dl, '0' ; Convert remainder to ASCII

dec di

8
Microprocessor and assembly language
mov [di], dl

inc cx ; Increment digit count

cmp ax, 0

jne ConvertLoop

; Display the string

lea dx, input_buffer + 2

mov ah, 09h

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

prompt1 db 'Enter the number of days in the month (1-31): $'

invalid_msg db 'Invalid input. Please enter a number between 1 and 31.$'

days_msg db 'Incremented days: $'

input_buffer db 4, 0, 0, 0, 0 ; Buffer to store input

days db 31 dup(?) ; Buffer to store days

9
Microprocessor and assembly language
.code

main proc

; Initialize data segment

mov ax, @data

mov ds, ax

InputLoop:

; Display the input prompt

lea dx, prompt1

mov ah, 09h

int 21h

; Read the input from the user

call ReadInteger

; Check if the input is valid (between 1 and 31)

cmp ax, 1

jl InvalidInput

cmp ax, 31

jg InvalidInput

; Store the number of days

mov cx, ax

; Display the incremented days message

10
Microprocessor and assembly language
lea dx, days_msg

mov ah, 09h

int 21h

; Initialize the days buffer with incremented values

mov bx, 0

mov si, cx

IncrementLoop:

mov al, bl

inc al

add al, '0'

mov days[bx], al

inc bx

loop IncrementLoop

; Display the incremented days

mov cx, si

mov bx, 0

DisplayDays:

mov dl, days[bx]

mov ah, 02h

int 21h

mov dl, ' '

int 21h

inc bx

11
Microprocessor and assembly language
loop DisplayDays

; Exit the program

mov ah, 4Ch

int 21h

InvalidInput:

; Display invalid input message

lea dx, invalid_msg

mov ah, 09h

int 21h

jmp InputLoop

; Subroutine to read an integer from the user

ReadInteger proc

lea dx, input_buffer

mov ah, 0Ah

int 21h

; Convert string to integer

lea si, input_buffer + 2 ; Offset to the first digit

xor ax, ax ; Clear AX

xor cx, cx ; Clear CX

ReadLoop:

mov cl, [si] ; Get character

12
Microprocessor and assembly language
cmp cl, 0 ; Check for end of string

je DoneRead

sub cl, '0' ; Convert ASCII to digit

mov bx, 10

mul bx ; Multiply AX by 10

add ax, cx ; Add digit to AX

inc si ; Move to the next character

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

prompt1 db 'Enter the student score (0-100): $'

invalid_msg db 'Invalid input. Please enter a number between 0 and 100.$'

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

; Initialize data segment

mov ax, @data

mov ds, ax

InputLoop:

; Display the input prompt

lea dx, prompt1

mov ah, 09h

int 21h

; Read the input from the user

call ReadInteger

; Check if the input is valid (between 0 and 100)

cmp ax, 0

jl InvalidInput

cmp ax, 100

jg InvalidInput

; Display Pass or Fail message

cmp ax, 50

14
Microprocessor and assembly language
jl Fail

lea dx, pass_msg

jmp DisplayMessage

Fail:

lea dx, fail_msg

DisplayMessage:

mov ah, 09h

int 21h

; Exit the program

mov ah, 4Ch

int 21h

InvalidInput:

; Display invalid input message

lea dx, invalid_msg

mov ah, 09h

int 21h

jmp InputLoop

; Subroutine to read an integer from the user

ReadInteger proc

lea dx, input_buffer

15
Microprocessor and assembly language
mov ah, 0Ah

int 21h

; Convert string to integer

lea si, input_buffer + 2 ; Offset to the first digit

xor ax, ax ; Clear AX

xor cx, cx ; Clear CX

ReadLoop:

mov cl, [si] ; Get character

cmp cl, 0 ; Check for end of string

je DoneRead

sub cl, '0' ; Convert ASCII to digit

mov bx, 10

mul bx ; Multiply AX by 10

add ax, cx ; Add digit to AX

inc si ; Move to the next character

jmp ReadLoop

DoneRead:

ret

ReadInteger endp

main endp

end main

16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy