Question

NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors...

NOTE: explain the lines in comments for better understanding

Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib.
The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers.
Fibonacci sequence is described by the following formula:
Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2).

The value of N is to be communicated to this Fib proceeddure via the EAX register
(i.e. main sets the value BEFORE it calls Fib) Fib should neatly prints out each
Fibonacci numbers, as it calculates them. It should put each number on its own line.
it should use WriteInt for the printing
(See http://programming.msjc.edu/asm/help/index.html?page=source%2Fabout.htm)

The main procedure need to ask the user HOW MANY of Fibonacci numbers to printout
and then reads in the value form the user (uses ReadDec -see bellow and maybe
http://programming.msjc.edu/asm/help/index.html?page=source%2Fabout.htm)
It should set the EAX register and then call the Fib procedure
Once the Fib procedure returns main should exit


.data
decNum DWORD ?

.code
read: call ReadDec
mov decNum,eax ;store good value



extra credit (optional)
We could do a better job of handling the input (invalid input)
Take a look at the documentation example from the above URL
and incorporate it your code

STARTER CODE FOR FIBONACCI SEQUENCE:

; Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2).
.data
prev DWORD 0
total DWORD 1
.code
Fib PROC USES EAX EBX ECX EDX
mov ecx, ; Loops N times
mov eax, ; puts prev into eax register (Fib(0) = 0 or n-2) into EAX
mov ebx, ; puts total into ebx register (Fib(1) = 1 or n-1) into EBX
L1:
mov ; move eax into edx register Fib(n) = Fib(n-2) EDX = EAX
add ; add prev and total Fib(n) = Fib(n-2) + Fib(n-1) EDX = EDX + EBX
mov ; prev = total save a copy for next iteration EAX = EBX
mov ; total = sum EBX = EDX
call WriteInt
loop L1
ret
Fib ENDP

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public main

main proc

mov ebx, 0 ; first number
mov ecx, 1 ; second number
; edx will contain the third number (ebx + ecx )

mov eax, fib-2 ; print fib numbers (not counting the first
and second because they will be printed in the begining)

mov edx, ebx
call WriteInt ; printing the first number

mov edx, ecx
call WriteInt ; printing the second number
fib:
mov edx, ebx
add edx, ecx ; edx = eax + ebx

call WriteInt

; now we have the third number in edx
; ebx = 1st, ecx = 2nd, edx = 3rd
; to prepare ebx and ecx for the next iteration, shift the values to the right
; ebx = 2nd, ecx = 3rd, edx = ?
mov ebx, ecx
mov ecx, edx

loop fibo
ret

main endp

end main

Add a comment
Know the answer?
Add Answer to:
NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code...

    X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code INCLUDE Irvine32.inc         .data       KeyPrompt BYTE "Enter the passphrase: ",0       TextPrompt BYTE "Enter the plaintest: ",0           str1 BYTE "The passphrase has length:",0           str2 BYTE "The plaintest has length:",0       KeyIs BYTE "The passphrase: ",0       PlainTextIs BYTE "The plaintext: ",0       CipherTextIs BYTE "The ciphertext: ",0       KMAX = 64                        ; passphrase buffer maximum size       BMAX = 128                       ; test...

  • URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment...

    URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment the start of each "code block" that performs one of the listed mathematical calculations. Comments go to the right of the actual code, all starting on the same column. Post ONLY your ASM file here to Blackboard when complete. // Global variables char a = 5; short b = 7; int   c = 11; int   d = 13; // Code int main() {    ...

  • Can someone explain how to get the answer to these two questions please? This is a...

    Can someone explain how to get the answer to these two questions please? This is a review for school. ; code fragment V Use this information and the code at the right to answer questions # 20-21. mov edx, OFFSET string mov ecx , MAXSIZE dec ecx call Readstring mov ecx, eax ; number of Given the following declarations for an IA-32 processor MAXSIZE 10 data ; digits entered ;initialize val string BYTE MAXSIZE DUP (?) mov val,0 mov esi,...

  • Create a flowchart for the following algorithm Program: (exchange.asm) Thia program exchanges every pair of values in a...

    Create a flowchart for the following algorithm Program: (exchange.asm) Thia program exchanges every pair of values in an array of even numbe red size model flat,stdcall stack 4096 ExitProcess PROTO, dwExitCode: dword data arrayDW dword 1, .code main PROC ov esi initialize index register with 0(i-0) loop counter mov ecx, LENGTHOF arrayDw) /2 L1 mov eax, arrayDW[esi) mov ebx, arrayDW [esi 41 mov arrayDW[esi], ebx move the item i into EAX 2move item 141 into EBX move item i+1 into...

  • I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates...

    I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates and prints out the first five Fibonacci numbers FO=0; F1=1; F2=1; F3=F1+F2; F4=F3+F2; F5=F4+F3 If we use 0, 1 and initial conditions the sequence would be: 0, 1, 1, 2, 3 Use the ebx, eax, and ecx registers. Note WriteHex, Writelnt, WriteDec, all use eax So use ebx for first and eax for second and ecx for temporary The calculation could go something like...

  • Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the...

    Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) + (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers. AddTwo program: ; AddTwo.asm - adds two 32-bit integers ; Chapter 3 example .386 .model flat,stdcall .stack 4096 ExitProcess PROTO, dwExitCode:DWORD .code main PROC mov eax,5 ; move 5 to the eax register add eax,6 ; add 6 to the...

  • Assembly Please answer the following above, compile and single step through the program, writing...

    Assembly Please answer the following above, compile and single step through the program, writing down the value of the destination for each instruction. 1. Using Visual Studio on the system, create a project using the code given below unsigned char short int int gArray 0x09, 0xFA, 0x5A, 0x18, 0x48, 0xAC, 0xD4, 0x71 ; cAr rays 1 [ ] = { 0:09, 0xfa, Ox5A, Ox18, 0x48, OxAC, OxD4, 0x71 }; gArray! [ ] = { Ox09, OxFA, Ox5A, Ox18, 0x48, OxAC,...

  • Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex...

    Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex and endIndex The program should create a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. In other words you can say that beginIndex is inclusive and endIndex is exclusive while getting the substring. Initialize the following values in...

  • Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the...

    Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the Carry flag. Question#2 Write a program that uses addition and subtraction to set and clear the Overflow flag. After each addition or subtraction, insert the call DumpRegs statement to display the registers and flags. Make sure to include an ADD instruction that sets both the Carry and Overflow flags. Using comments, explain how and why the Overflow flag was affected by each instruction. Question#3...

  • Looking for help understanding how this example program flows and works. Can you write comments next...

    Looking for help understanding how this example program flows and works. Can you write comments next to each line of code explaining what it does? Why does it use a switch? why not set the roman numerals as constants instead of a switch? Thank you!! //CPP program for converting roman into integers #include <iostream> #include <fstream> #include<cctype> #include<cstdlib> #include<string.h> using namespace std; int value(char roman) { switch(roman) { case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT