Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views16 pages

Al-Rouman (Micro Lab3&4 D1 - )

micro-lab

Uploaded by

Abrar Roman
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)
22 views16 pages

Al-Rouman (Micro Lab3&4 D1 - )

micro-lab

Uploaded by

Abrar Roman
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/ 16

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Fall, Year:2024), B.Sc. in CSE (Day)

Lab Report NO :3&4


Course Title: Microprocessor and Microcontroller Lab
Course Code: CSE 304 Section: 223-D1

Lab Experiment Name: Implementation of conditional statement and loop using


assembly language.

Student Details

Name ID

1. Md. Al-Rouman 223002036

Date : 10/09/2024 Submission


Course Teacher’s Name : Wahia Tasnim

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
1. TITLE OF THE LAB REPORT EXPERIMENT

Implementation of conditional statement and loop using assembly language.


• Take a character input from user, check whether the given character is vowel or not (a,e,i,o,u).
• Take input from user, you have to find out whether the given input is alphabet or digit.
• Take a number input from user, check whether the given number is divisible by 5 or not.
• Write an assembly program that converts a hexadecimal digit to its decimal equivalent. The
program
prompts the user to enter a hexadecimal digit and then displays its decimal equivalent. If the user
enters
an illegal character (not ’0’ to ’9’ or ’A’ to ’F’), the program provides an error message and allows
the
user to try again. The user can choose to continue or exit the program after each successful
conversion.
• Use loop to find out the summation of 1+3+5+7+.....+99. Also try to find out the summation using

• formula.

• • Take a number n from user. After that


find out the factorial of that number n. (Suppose
for n=5, you

• have to find out factorial= 1 × 2 × 3 × 4


× 5.

• • Take numbers as input from the user


and print whether the given number is odd or
even. You have to

• iterate the process until user press "N".


If user press "N" terminate your program
otherwise for given

• number print whether it is odd or even.

2. OBJECTIVES/AIM

The primary aim of this project is to develop an efficient x86 assembly program that
performs multiple computational tasks. It focuses on identifying whether a user-
provided character is a vowel and determining if it is an alphabet or a digit. The
program will also check if a number is divisible by 5, calculate the factorial of a user-
specified number, and sum odd numbers from 1 to 99 using both a loop and a formula.
Additionally, it will continuously prompt the user to input numbers and identify them
as odd or even until the user chooses to exit. Through these objectives, the project aims
to demonstrate fundamental assembly programming concepts and arithmetic
operations.

3. IMPLEMENTATION
.MODEL SMALL
.STACK 100H
.DATA .CODE
START:

4. TEST RESULT / OUTPUT

problem report 3:

section .data
vowel_msg db "Vowel", 0
not_vowel_msg db "Not a vowel", 0
alpha_msg db "Alphabet", 0
digit_msg db "Digit", 0
invalid_msg db "Neither alphabet nor digit", 0
div_by_5_msg db "Divisible by 5", 0
not_div_by_5_msg db "Not divisible by 5", 0
hex_prompt db "Enter hexadecimal digit: ", 0
error_msg db "Invalid hex digit", 0
dec_msg db "Decimal: ", 0
newline db 0xA
prompt_char db "Enter a character: ", 0
prompt_number db "Enter a number: ", 0

section .bss
char resb 1
num resb 10
hex_input resb 1

section .text
global _start

_start:
; Step 1: Input a character and check if it is a vowel
call input_char
call check_vowel

; Step 2: Check if the input is alphabet or digit


call check_alpha_digit

; Step 3: Input number and check divisibility by 5


call input_number
call check_divisible_by_5

; Step 4: Hexadecimal to decimal conversion


call convert_hex_to_decimal

; Exit the program


mov eax, 1
xor ebx, ebx
int 0x80
; Input a character from user
input_char:
mov eax, 4
mov ebx, 1
mov ecx, prompt_char
mov edx, 18
int 0x80

mov eax, 3
mov ebx, 0
mov ecx, char
mov edx, 1
int 0x80
ret
; Check if character is vowel
check_vowel:
mov al, [char]
cmp al, 'a'
je vowel
cmp al, 'e'
je vowel
cmp al, 'i'
je vowel
cmp al, 'o'
je vowel
cmp al, 'u'
je vowel
cmp al, 'A'
je vowel
cmp al, 'E'
je vowel
cmp al, 'I'
je vowel
cmp al, 'O'
je vowel
cmp al, 'U'
je vowel

; Not a vowel
mov eax, 4
mov ebx, 1
mov ecx, not_vowel_msg
mov edx, 12
int 0x80
jmp print_newline

vowel:
; Is a vowel
mov eax, 4
mov ebx, 1
mov ecx, vowel_msg
mov edx, 5
int 0x80
jmp print_newline

; Check if input is alphabet or digit


check_alpha_digit:
mov al, [char]
cmp al, '0'
jl not_digit
cmp al, '9'
jle is_digit

not_digit:
cmp al, 'A'
jl not_alpha
cmp al, 'Z'
jle is_alpha
cmp al, 'a'
jl not_alpha
cmp al, 'z'
jle is_alpha
jmp invalid_input

is_digit:
mov eax, 4
mov ebx, 1
mov ecx, digit_msg
mov edx, 5
int 0x80
jmp print_newline

is_alpha:
mov eax, 4
mov ebx, 1
mov ecx, alpha_msg
mov edx, 8
int 0x80
jmp print_newline

invalid_input:
mov eax, 4
mov ebx, 1
mov ecx, invalid_msg
mov edx, 27
int 0x80
jmp print_newline

; Input a number from user


input_number:
mov eax, 4
mov ebx, 1
mov ecx, prompt_number
mov edx, 15
int 0x80

mov eax, 3
mov ebx, 0
mov ecx, num
mov edx, 10
int 0x80
ret

; Check if the number is divisible by 5


check_divisible_by_5:
xor eax, eax
mov ecx, num
sub byte [ecx], '0'
movzx ebx, byte [ecx]

mov edx, 0
mov eax, ebx
mov ecx, 5
div ecx
cmp edx, 0
je divisible
jmp not_divisible

divisible:
mov eax, 4
mov ebx, 1
mov ecx, div_by_5_msg
mov edx, 17
int 0x80
jmp print_newline

not_divisible:
mov eax, 4
mov ebx, 1
mov ecx, not_div_by_5_msg
mov edx, 20
int 0x80
jmp print_newline

; Hexadecimal to decimal conversion


convert_hex_to_decimal:
call input_hex

hex_loop:
mov al, [hex_input]
cmp al, '0'
jl hex_error
cmp al, '9'
jle hex_convert

cmp al, 'A'


jl hex_error
cmp al, 'F'
jg hex_error

sub al, 'A'


add al, 10
jmp hex_display

hex_convert:
sub al, '0'

hex_display:
mov eax, 4
mov ebx, 1
mov ecx, dec_msg
mov edx, 9
int 0x80

add al, '0'


mov [hex_input], al
mov eax, 4
mov ebx, 1
mov ecx, hex_input
mov edx, 1
int 0x80
jmp print_newline

hex_error:
mov eax, 4
mov ebx, 1
mov ecx, error_msg
mov edx, 17
int 0x80
jmp hex_loop

; Input hexadecimal digit from user


input_hex:
mov eax, 4
mov ebx, 1
mov ecx, hex_prompt
mov edx, 23
int 0x80

mov eax, 3
mov ebx, 0
mov ecx, hex_input
mov edx, 1
int 0x80
ret

; Print a newline
print_newline:
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
ret

Problem of report 4:

section .data
prompt_num db "Enter a number: ", 0
odd_msg db "Odd", 0
even_msg db "Even", 0
prompt_continue db "Press N to quit, any key to continue: ", 0
newline db 0xA
continue_input db 1

section .bss
num resb 1

section .text
global _start

_start:
; Odd/Even checker loop
mov [continue_input], 'Y'
odd_even_loop:
cmp byte [continue_input], 'N'
je end_program
call input_number
mov al, [num]
sub al, '0'
test al, 1
jz print_even
call print_odd
jmp continue_check
print_even:
call print_even_msg
continue_check:
call ask_continue
jmp odd_even_loop

end_program:
mov eax, 1
xor ebx, ebx
int 0x80

; Input a number
input_number:
mov eax, 4
mov ebx, 1
mov ecx, prompt_num
mov edx, 16
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, num
mov edx, 1
int 0x80
ret

; Ask if the user wants to continue


ask_continue:
mov eax, 4
mov ebx, 1
mov ecx, prompt_continue
mov edx, 39
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, continue_input
mov edx, 1
int 0x80
ret

; Print "Odd"
print_odd:
mov eax, 4
mov ebx, 1
mov ecx, odd_msg
mov edx, 3
int 0x80
call print_newline
ret

; Print "Even"
print_even_msg:
mov eax, 4
mov ebx, 1
mov ecx, even_msg
mov edx, 4
int 0x80
call print_newline
ret

; Print a newline
print_newline:
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
ret

output:
Fig: a1
5. SUMMARY:
The combined assembly code effectively showcases fundamental assembly language operations,
including user input/output, arithmetic operations, and control flow. Specifically, it:

1. Odd/Even Check: Prompts the user for a single-digit number and determines whether it is
odd or even.

2. Summation of Odd Numbers: Iteratively calculates the sum of all odd numbers from 1
to 99, storing the result for output.

3. Factorial Calculation: Computes the factorial of a user-defined number through iterative


multiplication.

4. Continuation Prompt: Asks the user if they wish to continue entering numbers or
proceed to calculate the summation of odd numbers.

5. Formatted Output: Displays messages and results clearly to the user, handling both
character and numeric input.
This code illustrates essential concepts of assembly language programming and their
practical application in solving various computational tasks.

You might also like