将 BYTE 移动到 BYTE
Moving a BYTE to a BYTE
我在学习机器体系结构和汇编语言 class,我应该创建一个 MASM 程序来创建斐波那契数列直到用户定义的数字,该数字介于 1 和 46 之间。当我尝试将存储在标记为 buffer
的 BYTE
中的字符串传输到另一个标记为 user
的 BYTE
中,这是本书作者 ReadString
过程存储字符串的地方,我收到此构建输出:
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 ==========
我不确定为什么我不能将相同大小的对象移动到彼此中。我注释掉了用户部分并打印了缓冲区,它正确地将输入存储为字符串。非常感谢任何帮助。
***注意:我们使用的是 Assembly Language for the x86 Processor,第 7 版。由 Kip Irvine 编写,并使用他的 Irvine32 库。
; 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
有趣的新输出:
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 ==========
我更改了代码,让 ReadString 直接进入 User,输出是正确的。
;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
我在学习机器体系结构和汇编语言 class,我应该创建一个 MASM 程序来创建斐波那契数列直到用户定义的数字,该数字介于 1 和 46 之间。当我尝试将存储在标记为 buffer
的 BYTE
中的字符串传输到另一个标记为 user
的 BYTE
中,这是本书作者 ReadString
过程存储字符串的地方,我收到此构建输出:
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 ==========
我不确定为什么我不能将相同大小的对象移动到彼此中。我注释掉了用户部分并打印了缓冲区,它正确地将输入存储为字符串。非常感谢任何帮助。
***注意:我们使用的是 Assembly Language for the x86 Processor,第 7 版。由 Kip Irvine 编写,并使用他的 Irvine32 库。
; 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
有趣的新输出:
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 ==========
我更改了代码,让 ReadString 直接进入 User,输出是正确的。
;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