Reputation: 43
I am trying to write a program that spits out the Fibonacci sequence to the certain degree n, but using recursion and multiple linked files. So far, my approach has been to write the program in the single file and get it to work, and then translate it into multiple files. This has worked up until I tried to use the invoke
and proto
instructions to link the files. I am very confused where to even start.
Here is what I've tried and know works in a single file:
INCLUDE Irvine32.inc
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
.data
deg DWORD ?
prompt BYTE "Enter the degree of Fibonacci sequence: ",0
.code
main PROC
mov edx,OFFSET prompt
call WriteString
call ReadInt
mov deg,eax
mov ecx,0
push deg
call Fibonacci
add esp,4
call WriteDec
call Crlf
INVOKE ExitProcess,0
main ENDP
Fibonacci PROC
add ecx,1
push ebp
mov ebp,esp
sub esp,4
mov eax,[ebp+8]
cmp eax,2
je L1
cmp eax,1
je L1
dec eax
push eax
call Fibonacci
mov [ebp-4],eax
dec DWORD PTR [esp]
call Fibonacci
add esp,4
add eax,[ebp-4]
jmp EndFib
L1:
mov eax,1
EndFib:
mov esp,ebp
pop ebp
ret
Fibonacci ENDP
END main
I know for a fact that the above code compiles, but attempting to split this up into multiple files always leads to a build error. Here are the 3 files from what I attempted to get working:
main.asm
INCLUDE Irvine32.inc
INCLUDE external.inc
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
.data
.code
main PROC
mov ecx,0
push 3
invoke Fibonacci
add esp,4
call WriteDec
call Crlf
INVOKE ExitProcess,0
main ENDP
END main
fib.asm
INCLUDE Irvine32.inc
INCLUDE external.inc
.code
Fibonacci PROC
add ecx,1
push ebp
mov ebp,esp
sub esp,4
mov eax,[ebp+8]
cmp eax,2
je L1
cmp eax,1
je L1
dec eax
push eax
call Fibonacci
mov [ebp-4],eax
dec DWORD PTR [esp]
call Fibonacci
add esp,4
add eax,[ebp-4]
jmp EndFib
L1:
mov eax,1
; dec eax
EndFib:
mov esp,ebp
pop ebp
ret
Fibonacci ENDP
END
external.inc
INCLUDE Irvine32.inc
Fibonacci PROTO
When this fails I get a window that says
There were build errors. Would you like to continue and run the last successful build?
My friend told me that I should get error messages that show me which line the program tripped up on, but I only see this and the build output which I will put below. Is this normal?
1>------ Build started: Project: ModSum, Configuration: Debug Win32 ------
1>Assembling main.asm...
1>c:\irvine\SmallWin.inc(11): warning A4011: multiple .MODEL directives found : .MODEL ignored
1>c:\irvine\SmallWin.inc(245): error A2163: non-benign structure redefinition: incorrect initializers : CONSOLE_SCREEN_BUFFER_INFO
1>c:\irvine\SmallWin.inc(246): error A2163: non-benign structure redefinition: incorrect initializers : CONSOLE_SCREEN_BUFFER_INFO
1>c:\irvine\SmallWin.inc(248): error A2163: non-benign structure redefinition: incorrect initializers : CONSOLE_SCREEN_BUFFER_INFO
1>c:\irvine\SmallWin.inc(249): error A2163: non-benign structure redefinition: incorrect initializers : CONSOLE_SCREEN_BUFFER_INFO
1>c:\irvine\SmallWin.inc(258): error A2163: non-benign structure redefinition: incorrect initializers : KEY_EVENT_RECORD
1>c:\irvine\SmallWin.inc(261): error A2163: non-benign structure redefinition: incorrect initializers : KEY_EVENT_RECORD
1>c:\irvine\SmallWin.inc(262): error A2161: non-benign structure redefinition: too few labels : KEY_EVENT_RECORD
1>c:\irvine\SmallWin.inc(262): error A2163: non-benign structure redefinition: incorrect initializers : KEY_EVENT_RECORD
1>c:\irvine\SmallWin.inc(265): error A2163: non-benign structure redefinition: incorrect initializers : MOUSE_EVENT_RECORD
1>c:\irvine\SmallWin.inc(272): error A2163: non-benign structure redefinition: incorrect initializers : WINDOW_BUFFER_SIZE_RECORD
1>c:\irvine\SmallWin.inc(287): error A2163: non-benign structure redefinition: incorrect initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(288): error A2163: non-benign structure redefinition: incorrect initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(289): error A2163: non-benign structure redefinition: incorrect initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(290): error A2163: non-benign structure redefinition: incorrect initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(290): error A2164: non-benign structure redefinition: too few initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(291): error A2164: non-benign structure redefinition: too few initializers : INPUT_RECORD
1>c:\irvine\SmallWin.inc(293): error A2161: non-benign structure redefinition: too few labels : INPUT_RECORD
1>c:\irvine\SmallWin.inc(293): error A2164: non-benign structure redefinition: too few initializers : INPUT_RECORD
1>main.asm(7): warning A4011: multiple .MODEL directives found : .MODEL ignored
1>MASM : fatal error A1016: Internal error
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\main.obj" /I "c:\irvine" /W3 /errorReport:prompt /Tamain.asm" exited with code -1073741819.
1>Done building project "ModSum.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Huge thanks to anyone who can spare some time or assistance, I've been working on this on my own for a while and can't figure it out.
Upvotes: 0
Views: 731
Reputation: 28921
I'm thinking that external.inc should not include Irvine32.inc, since the .asm files include both. The end result is that Irvine32.inc is being included twice for each .asm file.
Upvotes: 1