将BYTE移动到BYTE

时间:2015-10-21 23:49:01

标签: visual-studio assembly visual-studio-2015 masm irvine32

我在机器架构和汇编语言类中,我应该创建一个MASM程序,创建Fibonacci序列,直到用户定义的数字,包括在1到46之间。当我尝试传输字符串时存储在BYTE标记的buffer(书籍作者ReadString过程存储字符串的位置)存储到标记为BYTE的另一个user,我收到此构建输出:

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 ==========

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

***注意:我们正在使用x86处理器的汇编语言,第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 ==========

1 个答案:

答案 0 :(得分:1)

我更改了代码,因此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