将字节移动到字节



我在机器体系结构和汇编语言课上,我应该创建一个MASM程序,该程序创建斐波那契数列,直到用户定义的数字,包括1到46之间。当我尝试将存储在标记为 bufferBYTE中的字符串(这是书籍作者ReadString过程存储字符串的地方(传输到另一个标记为 userBYTE时,我收到以下构建输出:

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)MSBuildMicrosoft.Cppv4.0V140BuildCustomizationsmasm.targets(50,5): error MSB3721: The command "ml.exe /c /nologo /Sg /Zi /Fo"Debugfibonacci.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 ==========

不确定为什么我不能移动到相同大小的物体中。我注释掉了用户部分并打印了缓冲区,它正确地将输入存储为字符串。任何帮助将不胜感激。

注意:我们使用 Kip Irvine 的 x86 处理器汇编语言第 7 版一书,并使用他的 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)MSBuildMicrosoft.Cppv4.0V140BuildCustomizationsmasm.targets(50,5): error MSB3721: The command "ml.exe /c /nologo /Sg /Zi /Fo"Debugfibonacci.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

最新更新