【发布时间】:2016-06-13 07:14:55
【问题描述】:
我原来的作业问题是这样的:
编写一个程序,使用下面的变量和 MOV 指令将值从 bigEndian 复制到 littleEndian,颠倒字节顺序。该数字的 32 位值被理解为 12345678 十六进制。
.data bigEndian BYTE 12h, 34h, 56h, 78h littleEndian DWORD?
我认为我的代码是正确的,但我不知道为什么会出现此错误。这是我的代码和错误:
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
bigEndian BYTE 12h, 34h, 56h, 78h
littleEndian DWORD ?
.code
main PROC
mov eax, DWORD PTR bigEndian; eax = 87654321h
mov littleEndian, eax
invoke ExitProcess, 0
main ENDP
END main
1>------构建开始:项目:BigEndianLittleEndian,配置:调试 Win32 ------
1> 组装 BigEndiantoLittleEndian.asm...
1>BigEndiantoLittleEndian.asm(20):错误 A2008:语法错误
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\masm.targets(50,5):错误 MSB3721:命令“ml.exe /c /nologo /Zi /Fo"Debug\BigEndiantoLittleEndian.obj" /W3 /errorReport:prompt /TaBigEndiantoLittleEndian.asm" 退出,代码为 1。
========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
我该如何解决这个错误?
这里是更新的代码:
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
bigEndian BYTE 12h, 34h, 56h, 78h
littleEndian DWORD ?
.code
main PROC
mov ah, byte ptr bigEndian+0
mov al, byte ptr bigEndian+1
mov word ptr littleEndian+2,ax;here I want to move my now full register into the 32bit register eax.
mov ah, byte ptr bigEndian+2
mov al, byte ptr bigEndian+3
mov word ptr littleEndian+2,ax here I want to move my now full register into the 32bit register eax which results in the order being reversed.
invoke ExitProcess, 0
main ENDP
END main
我得到的错误
1>----- 构建开始:项目:BigEndianLittleEndian,配置:调试 Win32 ------
1> 组装 BigEndiantoLittleEndian.asm...
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(708,9): error MSB4030: "main" is an invalid value for the " “链接”任务的 NoEntryPoint”参数。 “NoEntryPoint”参数的类型为“System.Boolean”。
========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
【问题讨论】:
-
我没有看到任何反转字节的代码。我的猜测是您的 ASM 错误来自第一个 mov 语句。
-
mov eax, DWORD PTR bigEndian, eax = 87654321h将是一个问题。mov需要 2 个操作数。不是 3. 不确定, eax = 87654321h是什么意思。 -
你看到它抛出错误的那一行了吗?
-
看起来
eax = 87654321h应该是评论(即; eax = 87654321h)。不过评论是不正确的,因为eax会得到78563412h的值。 -
这就是我感到困惑的地方。我试图声明我的代码,但我仍然会收到错误消息。 eax=87654321h 应该是我会修复的评论。在这一点上,我猜测是因为我试图跟随这本书,但没有例子。我只知道少了一件。我希望你们能够为我挑选出来并解释为什么会这样。我确实相信它与声明值 12345678h 或我所拥有的相反。感谢大家的帮助。