Assignment 2 – ASM program-Fibonacci number sequence- displays the string in reverse order-each lower-case letter converted to its corresponding upper-case letter
Click Here to enroll in this course now
60-266 – Assignment #2
Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by:
Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1)
Thus, if the input is N = 10, your program Ass1-Q1.exe should display the following single line:
Fibonacci sequence with N = 10 is: 0 1 1 2 3 5 8 13 21 34 55
Answer(partial):
INCLUDE Irvine32.inc
.data
msg1 byte "Please enter a number", 0dh, 0ah, 0
msg2 byte "Febonacci sequence is: ", 0
spce byte " ", 0
.code
main PROC
mov edx, OFFSET msg1
call WriteString
call ReadInt
mov ecx, eax; print N numbers
call WriteString
L1:
add ebx, eax; generate next number
xchg eax, ebx; step up the sequence
loop L1
call crlf
exit
main ENDP
END main
Programming Exercise 2 :
Write an ASM program that prompts the user to enter a string of at most 128 characters and then displays the string in reverse order, with: each upper-case letter converted to its corresponding lower-case letter, and each lower-case letter converted to its corresponding upper-case letter. The program should also display the number of lowercase characters after displaying the output string. For instance, a sample execution of “Ass2-Q2.exe” with the input string “An Input Line!” is shown below
——————————————
C:\Programming\asm>Ass1-Q2
Enter a string of at most 128 characters: An Input Line!
Here it is in LOWERCASE and in reverse order:
!ENIl TUPNi Na
There are 3 lower-case characters.
C:\Programming\asm>
——————————————
HINT: Solving this question in the following sequential order will be much easier; though you can solve the way you want. 1) First, read the string from the keyboard into a memory variable. 2) Second, convert lowercases to uppercases and uppercases to lowercases; be careful here. 3) Third, print the resulting string in reverse order, by using indirect
addressing (or indexed addressing, if you wish); be also careful here since there are two possible ways: you can either reverse the initial string first then display the resulting reversed string, or you can directly display the initial string in reverse order.
You should correctly decide how, when, and where (in the hint above) to perform the count of the number of lower-case characters.
If the user enters more than 128 characters, only the first 128 characters must be processed (the rest are ignored but make sure that you cannot write outside the memory you have allocated for storing the string).
Also, try to make use of data-related operators as much as possible, such as SIZEOF, TYPE, LENGTHOF, DUP or PTR, in order to make your program as flexible as possible (and as short —efficient— as possible); see Chapt_04-c.
Answer(partial):
INCLUDE Irvine32.inc
.data
buffer byte 128 dup(0)
msg1 byte "Enter a string of at most 128 characters:", 0dh, 0ah, 0
msg2 byte " Here it is in LOWERCASE and in reverse order: ", 0dh, 0ah, 0
msg3 byte 0dh, 0ah, " There are ",0
msg4 byte " lower-case characters ", 0dh, 0ah, 0
countLower byte 0
.code
main PROC
mov ecx, 0
mov eax, 0
mov edx,OFFSET msg1
call WriteString
read_again:
test_lower :
cmp al, 7Ah
ja store
sub al, 20h
store:
push eax
inc ecx
jmp read_again
endread:
lea esi, buffer
display :
again:
pop eax
call WriteChar
quit:
exit
main ENDP
END main

Leave a reply