I am in a Machine Architecture and Assembly Language class, and I am supposed to create a MASM program that creates the Fibonacci sequence up to a user defined number, that is inclusively between 1 and 46. When I try to transfer the string stored in a BYTE
labeled buffer
, which is where the book authors ReadString
procedure stores a string, to another BYTE
labeled user
, I receive this build output:
1>------ Build started: Project: MASM2, Configuration: Debug Win32 ------
1> Assembling fibonacci.asm...
1>fibonacci.asm(39): error A2070: invalid instruction operands
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\masm.targets(50,5): error MSB3721: The command "ml.exe /c /nologo /Sg /Zi /Fo"Debug\fibonacci.obj" /Fl"MASM2.lst" /I "c:\Irvine" /W3 /errorReport:prompt /Tafibonacci.asm" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am not sure why I can't move to same sized objects into each other. I commented out the user parts and printed the buffer, and it is storing the input as a string correctly. Any help is greatly appreciated.
***Note: We are using the book Assembly Language for the x86 Processor, 7th Ed. by Kip Irvine, and using his Irvine32 Library.
; Calculate Fibonacci to the nth degree
INCLUDE Irvine32.inc
.data
buffer BYTE 21 DUP(0)
welcome BYTE "Welcome to Fibonacci! My name is Zach, I will be your programmer today!", 0
question BYTE "What is your name?: ", 0
greet BYTE "Hello, ", 0
user BYTE ?
prompt BYTE "Enter a number from 1 to 46: ", 0
debrief BYTE "GoodBye"
input SDWORD ?
fib DWORD ?
.code
main proc
call Clrscr
;Print Welcome Screen
mov edx,OFFSET welcome
call WriteString
call Crlf
;Get Username and Greet
mov edx,OFFSET question
call WriteString
call Crlf
mov edx,OFFSET buffer
mov ecx,SIZEOF buffer
call ReadString
mov user, buffer
mov edx,OFFSET greet
call WriteString
mov edx,OFFSET buffer
call WriteString
call Crlf
;Get Input-- 1 to 46
mov edx,OFFSET prompt
call WriteString
call ReadInt
mov input,eax
;Validate n
;Calculate-5 terms per line w/5 spaces between
mov ecx,input
mov al, ','
mov eax,1
call WriteDec
start:
call WriteChar
call WriteDec
mov fib, eax
add eax,fib
LOOP start
;Debrief
call Crlf
mov edx,OFFSET debrief
call WriteString
invoke ExitProcess,0
main endp
end main
Fun New Output:
1>------ Build started: Project: MASM2, Configuration: Debug Win32 ------
1> Assembling fibonacci.asm...
1>fibonacci.asm(44): error A2022: instruction operands must be the same size
1>fibonacci.asm(45): error A2022: instruction operands must be the same size
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\masm.targets(50,5): error MSB3721: The command "ml.exe /c /nologo /Sg /Zi /Fo"Debug\fibonacci.obj" /Fl"MASM2.lst" /I "c:\Irvine" /W3 /errorReport:prompt /Tafibonacci.asm" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I changed the code so ReadString goes straight to User, and the output is correct.
;Get Username and Greet
mov edx,OFFSET question
call WriteString
call Crlf
mov edx,OFFSET user
mov ecx,SIZEOF user
call ReadString
mov edx,OFFSET greet
call WriteString
mov edx,OFFSET user
call WriteString
call Crlf