0% found this document useful (0 votes)
5 views

Microprocessor and Assembly Language

The document is an assignment submission by Asad Yar on microprocessor and assembly language programming. It includes ten questions that involve user input and various calculations such as reversing a string, arithmetic operations, generating patterns, and computing sums of even numbers, squares, and cubes. Each question is accompanied by assembly code that implements the required functionality.

Uploaded by

Ali Asad Watto
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Microprocessor and Assembly Language

The document is an assignment submission by Asad Yar on microprocessor and assembly language programming. It includes ten questions that involve user input and various calculations such as reversing a string, arithmetic operations, generating patterns, and computing sums of even numbers, squares, and cubes. Each question is accompanied by assembly code that implements the required functionality.

Uploaded by

Ali Asad Watto
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Microprocessor and Assembly Language

Assignment No: 2nd


Submitted By: Asad Yar
Registration No: FA21-BCS-212
Date of Submission: 26
December 2024
Campus: Abbottabad
Question 01
Prompt the user to enter some string and print that string in
reverse order. Maximum length of string is around 10 letters
(e.g if APPLE is input string, then result should be ELPPA)
.data
str BYTE 10 DUP(?), 0
.code
main PROC
call WriteString
call ReadString
lea esi, str
mov ecx, 0
count:
mov al, [esi + ecx]
cmp al, 0
je reverse
inc ecx
jmp count
reverse:
dec ecx
rev_loop:
cmp ecx, -1
jl end
mov al, [esi + ecx]
call WriteChar
dec ecx
jmp rev_loop
end:
call Crlf
invoke ExitProcess, 0
main ENDP
END main

QUESTION 2
Take two numbers from users , store them in variables num1
and num2 respectively. Calculate their sum, difference,
product, quotient and remainder and print the result as per
following format: Num1=5 and Num2=3 Num1+num2= 8
Num1-num2=2 Num1*num2=15 quotient(Num1/num2)=1
remainder(Num1/Num2)=2
.data
num1 DWORD ?
num2 DWORD ?
.code
main PROC
call WriteString
call ReadInt
mov num1, eax
call WriteString
call ReadInt
mov num2, eax
calc:
mov eax, num1
add eax, num2
call WriteDec
call Crlf
sub eax, num2
sub eax, num2
call WriteDec
call Crlf
imul eax, num2
call WriteDec
call Crlf
mov eax, num1
cdq
idiv num2
call WriteDec
call Crlf
mov eax, edx
call WriteDec
call Crlf
3478922131
invoke ExitProcess, 0
main ENDP
END main

Question 3
Print the following format
*
**
***
****
*****
.data
newline BYTE 10, 0
.code
main PROC
mov ecx, 5
row_loop:
mov edx, ecx
mov eax, 6
sub eax, ecx
print_star:
cmp eax, 0
je newline
call WriteChar
dec eax
jmp print_star
newline:
call WriteString
loop row_loop
invoke ExitProcess, 0
main ENDP
END main

Question 4
Print the even numbers from 0 to N Where N is user input.
.data
num DWORD ?
.code
main PROC
call WriteString
call ReadInt
mov num, eax
xor ecx, ecx
mov eax, 2
even_loop:
cmp eax, num
jg end
call WriteDec
call Crlf
add eax, 2
jmp even_loop
end:
invoke ExitProcess, 0
main ENDP
END main

Question 5
Print the first N multiple of 3 ; where N is User input.
.data
num DWORD ?
.code
main PROC
call WriteString
call ReadInt
mov ecx, eax
mov eax, 3
mul_loop:
mov edx, 0
imul edx, ecx, 3
call WriteDec
call Crlf
loop mul_loop
invoke ExitProcess, 0
main ENDP
END main

Question 6
Print the first N prime numbers from 1 to N, where N is
User Input.
.data
num DWORD ?
.code
main PROC
call WriteString
call ReadInt
mov num, eax
xor edx, edx
mov ecx, 2
prime_loop:
mov eax, ecx
mov ebx, 2
check_loop:
cmp ebx, ecx
je prime_found
mov edx, 0
div ebx
test edx, edx
jz skip_prime
inc ebx
jmp check_loop
prime_found:
call WriteDec
call Crlf
dec num
skip_prime:
inc ecx
cmp num, 0
jne prime_loop
invoke ExitProcess, 0
main ENDP
END main

Question 7
Print the first N elements of Fibonacci sequence.
(Fibonacci Sequence is 0 1 1 2 3 5 8 …)
.data
num DWORD ?
a DWORD 0
b DWORD 1
temp DWORD ?
.code
main PROC
call WriteString
call ReadInt
mov ecx, eax
call WriteDec
call Crlf
mov eax, b
call WriteDec
call Crlf
fib_loop:
mov eax, a
add eax, b
mov temp, eax
call WriteDec
call Crlf
mov eax, b
mov a, eax
mov b, temp
loop fib_loop
invoke ExitProcess, 0
main ENDP
END main
Question 8
Print the sum of first n even numbers; N is User input
.data
num DWORD ?
sum DWORD 0
.code
main PROC
call WriteString
call ReadInt
mov ecx, eax
xor eax, eax
calc_sum:
shl ecx, 1
add sum, ecx
dec ecx
loop calc_sum
mov eax, sum
call WriteDec
call Crlf
invoke ExitProcess, 0
main ENDP
END main

Question 9
: Print the sum of square of N natural numbers ; N is user
Input
.data
num DWORD ?
sum DWORD 0
.code
main PROC
call WriteString
call ReadInt
mov ecx, eax
xor eax, eax
square_sum:
imul eax, ecx
add sum, eax
dec ecx
loop square_sum
call WriteDec
call Crlf
invoke ExitProcess, 0
main ENDP
END main

Question 10
: Print the sum of cube of first N natural numbers, where N
is input.
data
num DWORD ?
sum DWORD 0
.code
main PROC
call WriteString
call ReadInt
mov ecx, eax
cube_sum:
mov eax, ecx
imul eax, ecx
imul eax, ecx
add sum, eax
dec ecx
loop cube_sum
call WriteDec
call Crlf
invoke ExitProcess, 0
main ENDP
END main

You might also like