Write a program that generates the first 47 values in the Fibonacci series, stor
ID: 3813458 • Letter: W
Question
Write a program that generates the first 47 values in the Fibonacci series, stores them in an array of doublewords, and then writes the array to a file on the hard drive.
You do not need to worry about doing any error checking of the file I/O since the topic has yet to be covered.
Your output file should be exactly 188 bytes long when completed since that is the amount of memory required to store 47 doublewords.
Use debug.exe or Visual Studio or any other program that can open and inspect the file in hexadecimal format.
From there convert the hexadecimal values to decimal and check for correctness in Microprocessor Assembly Language for x86 Intel Processors. Please provide output screen.
Explanation / Answer
INCLUDE Irvine32.inc
.data
COUNT_FIB = 45 ; generate after first 2 number
sizeOfBuffer = 188
firstNum = 1
secNum = 1
handleFile DWORD ?
file_name BYTE "a.bin",0 ; set file path
array DWORD 47 DUP(?)
tmp1 DWORD ?
tmp2 DWORD ?
tmp3 DWORD ?
.code
main PROC
mov esi,0
mov array[esi],firstNum
mov eax,array[esi]
mov tmp1,eax
add esi,4
mov eax,0
mov array[esi],secNum
mov eax,array[esi]
mov tmp2,eax
add esi,4
call dumpregs
mov ecx, COUNT_FIB
gen_fibonacci:
mov eax,0
mov ebx,0
mov eax,tmp1
mov ebx,tmp2
add eax,ebx
mov tmp3,eax
mov array[esi],eax
mov tmp1,ebx
mov tmp2,eax
add esi,4
loop gen_fibonacci
mov edx,OFFSET file_name
call CreateOutputFile
mov handleFile,eax
mov edx,OFFSET array
mov ecx,sizeOfBuffer
call WriteToFile
mov eax,handleFile
call CloseFile
exit
main ENDP
END main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.