Assembly io.h出错有什么问题?
这是我课本上直接写的,不知道是什么原因造成的。它以前工作过 我正在使用的图书代码:Assembly io.h出错有什么问题?,assembly,compiler-errors,header,Assembly,Compiler Errors,Header,这是我课本上直接写的,不知道是什么原因造成的。它以前工作过 我正在使用的图书代码: ; Input x and y, call procedure to evaluate 3*x+7*y, display result ; Author: R. Detmer ; Date: 6/2013 .586 .MODEL FLAT INCLUDE io.h .STACK 4096 .DATA number1 DWORD ? number2 DWORD ? prompt1 BYTE
; Input x and y, call procedure to evaluate 3*x+7*y, display result
; Author: R. Detmer
; Date: 6/2013
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
number1 DWORD ?
number2 DWORD ?
prompt1 BYTE "Enter first number x", 0
prompt2 BYTE "Enter second number y", 0
string BYTE 20 DUP (?)
resultLbl BYTE "3*x+7*y", 0
result BYTE 11 DUP (?), 0
.CODE
_MainProc PROC
input prompt1, string, 20 ; read ASCII characters
atod string ; convert to integer
mov number1, eax ; store in memory
input prompt2, string, 20 ; repeat for second number
atod string
mov number2, eax
push number2 ; 2nd parameter
push number1 ; 1st parameter
call fctn1 ; fctn1(number1, number2)
add esp, 8 ; remove parameters from stack
dtoa result, eax ; convert to ASCII characters
output resultLbl, result ; output label and result
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
; int fctn1(int x, int y)
; returns 3*x+7*y
fctn1 PROC
push ebp ; save base pointer
mov ebp, esp ; establish stack frame
push ebx ; save EBX
mov eax, [ebp+8] ; x
imul eax, 3 ; 3*x
mov ebx, [ebp+12] ; y
imul ebx, 7 ; 7*y
add eax, ebx ; 3*x + 7*y
pop ebx ; restore EBX
pop ebp ; restore EBP
ret ; return
fctn1 ENDP
END
错误:
Error 101 error A1012: error count exceeds 100; stopping assembly C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\io.h 102 1 console32
Error 3 error A2008: syntax error : * C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\io.h 3 1 console32
Error 13 error A2044: invalid character in file C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\io.h 14 1 console32
Error 102 error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\Source.obj" /W3 /errorReport:prompt /Fl /TaSource.asm" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\masm.targets 49 5 console32
我去掉了重复的错误,使它看起来更干净/整洁。
我试图编辑头文件以删除注释,但我没有写入头文件的权限。我也不认为有必要编辑这个文件,因为它曾经工作过。我正在使用书籍、文件和代码
我在我的笔记本电脑上也试过了,它也给了我同样的错误。我在两台机器上都使用visual studio 2012
如果你需要更多信息,请告诉我
在windows32汇编程序中使用io.h。
打开VS-->新项目-->c/c++-->Windows32(非控制台32)-->空白项目。
在“解决方案资源管理器”中,右击“源文件夹”> >添加新项-> C++文件(.CPP)并用扩展名.ASM而不是.CPP来指定您的名称。
代码:
在windows32汇编程序中使用io.h。
打开VS-->新项目-->c/c++-->Windows32(非控制台32)-->空白项目。
在“解决方案资源管理器”中,右击“源文件夹”> >添加新项-> C++文件(.CPP)并用扩展名.ASM而不是.CPP来指定您的名称。
代码:
我道歉!我刚刚意识到我不能使用io.h,因为我正在编写一个控制台应用程序,这段代码是针对windows应用程序的
对于其他有此问题的人,如果您正在编写控制台程序,您不能使用io.h,控制台程序中没有输入/输出,如果您需要输入/输出,您必须使用windows应用程序。@RossRidge对此我不确定,我知道它是用C编写的。但是,它在windows 32应用程序中工作,而不是在控制台32应用程序中工作。并且,您不能在控制台程序集应用程序中使用io.h。不过io.h在windows32汇编程序中可以工作。如果您愿意,我可以向您展示我制作的一个使用io.h并可以工作的windows32汇编程序。我已经做了大约3个这样的工作。。。。谷歌it老兄。@RossRidge买这本书:你需要研究那本书。您需要遵循在windows32汇编程序中使用io.h的编程练习。我告诉你,它是有效的。代码是本书的核心部分,它是有效的。我只是用了控制台应用程序projrct而不是windows应用程序。@MichaelPetch您可能是对的,这里涉及了不同的
io.h
,但OP“GeekDewd”对它在“控制台应用程序”中不起作用提出了截然不同的论点。他之所以没有说他使用了书中的io.h
,是因为在你发表评论之前,他根本不知道它的存在。
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
firstInput DWORD ? ; Reserve DWORD sized named memory for 1st input
secondInput DWORD ? ; Reserve DWORD sized named memory for 2nd input
prompt1 BYTE "Enter first number", 0 ; Prompt user for the first input
prompt2 BYTE "Enter second number", 0 ; Prompt user for the second input
inputString BYTE 11 DUP (?) ; Reserve memory for to store inputs
; as integer max integer is 10 digits big
resultLbl BYTE "GCD", 0 ; label for dialogBox
resultLb2 BYTE "The GCD is:" ; String to be diplayed in the dialogBox
gcdResult BYTE 10 DUP (?), 0 ; to display " The GCD is:" and then gcdInput
.CODE
_MainProc PROC
;************************ GET FIRST INPUT ************************
input prompt1, inputString, 11 ; read ASCII characters
; Max length for integer is 10 digits
atod inputString ; convert to integer
mov firstInput, eax ; store in memory
;************************ GET SECOND INPUT ***********************
; repeat for second number
input prompt2, inputString, 11 ; read ASCII characters
atod inputString ; convert to integer
mov secondInput, eax ; store in memory
;******************** THEORY IN PSUDOCODE *******************
; gcdInput is firstInput
; remainder is secondInput
; loop:
; dividend is gcdInput
; gcdInput is remainder
;
; firstInput and secondInput are reserved memory
; dividend is stored in EAX ---> numerator
; gcdInput is stored in EBX ---> denominator
; remainder is stored in EDX ---> remainder
; quotient is stored in EAX ---> quotient
; EAX/EBX ---> quotient will be stored in EAX
; remainder will be stored in EDX
; based on CPU logic
;************************ FIND GCD OF 2 NUMBERS ******************
mov EBX, firstInput ; Copy named memory to EBX
mov EDX, secondInput ; Copy named memory to EDX
findTheGCD: ; DO
mov EAX, EBX ; Copy gcdInput to EAX. Second pass and so on will
; copy the denominator to the numerator
mov EBX, EDX ; Copy remainder to EBX Second pass and so on will
; copy the remainder to the denominator
mov EDX, 0 ; cdq is for signed, so instead of cdq move 0 to EDX.
; cdq expands EAX to EDX:EAX filling EDX with the sign bit
; Since our numbers are positive our sign bit is 0
; So filling EDX with 0's is the same as cdq would do.
; We are not using cdq and we are using div because we
; are working with unsigned integers.
; Clear out previous remainder
div EBX ; Divide EDX:EAX/EBX (dividend/gcdInput)
; second pass and so on will divide
; the denominator by the numerator repeatedly
; until the remainder is 0
; Quotient does not matter in this situation
; After the division process EAX will contain the quotient
; And EDX will contain the remainder, thus the 0's we filled
; it with will be overwritten with the remainder
cmp EDX, 0 ; Compare EDX (remainder) to 0
; Since the 0's were overwritten with the remainder after the division
; the compare will see the new remainder NOT the 0's that was in it before!!
jne findTheGCD ; UNTIL ( remainder == 0 )
;************************ PRINT THE GCD TO SCREEN ******************
dtoa gcdResult, EBX ; convert to ASCII characters
output resultLbl, resultLb2 ; output label and gcd string
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
firstInput DWORD ? ; Reserve DWORD sized named memory for 1st input
secondInput DWORD ? ; Reserve DWORD sized named memory for 2nd input
prompt1 BYTE "Enter first number", 0 ; Prompt user for the first input
prompt2 BYTE "Enter second number", 0 ; Prompt user for the second input
inputString BYTE 11 DUP (?) ; Reserve memory for to store inputs
; as integer max integer is 10 digits big
resultLbl BYTE "GCD", 0 ; label for dialogBox
resultLb2 BYTE "The GCD is:" ; String to be diplayed in the dialogBox
gcdResult BYTE 10 DUP (?), 0 ; to display " The GCD is:" and then gcdInput
.CODE
_MainProc PROC
;************************ GET FIRST INPUT ************************
input prompt1, inputString, 11 ; read ASCII characters
; Max length for integer is 10 digits
atod inputString ; convert to integer
mov firstInput, eax ; store in memory
;************************ GET SECOND INPUT ***********************
; repeat for second number
input prompt2, inputString, 11 ; read ASCII characters
atod inputString ; convert to integer
mov secondInput, eax ; store in memory
;******************** THEORY IN PSUDOCODE *******************
; gcdInput is firstInput
; remainder is secondInput
; loop:
; dividend is gcdInput
; gcdInput is remainder
;
; firstInput and secondInput are reserved memory
; dividend is stored in EAX ---> numerator
; gcdInput is stored in EBX ---> denominator
; remainder is stored in EDX ---> remainder
; quotient is stored in EAX ---> quotient
; EAX/EBX ---> quotient will be stored in EAX
; remainder will be stored in EDX
; based on CPU logic
;************************ FIND GCD OF 2 NUMBERS ******************
mov EBX, firstInput ; Copy named memory to EBX
mov EDX, secondInput ; Copy named memory to EDX
findTheGCD: ; DO
mov EAX, EBX ; Copy gcdInput to EAX. Second pass and so on will
; copy the denominator to the numerator
mov EBX, EDX ; Copy remainder to EBX Second pass and so on will
; copy the remainder to the denominator
mov EDX, 0 ; cdq is for signed, so instead of cdq move 0 to EDX.
; cdq expands EAX to EDX:EAX filling EDX with the sign bit
; Since our numbers are positive our sign bit is 0
; So filling EDX with 0's is the same as cdq would do.
; We are not using cdq and we are using div because we
; are working with unsigned integers.
; Clear out previous remainder
div EBX ; Divide EDX:EAX/EBX (dividend/gcdInput)
; second pass and so on will divide
; the denominator by the numerator repeatedly
; until the remainder is 0
; Quotient does not matter in this situation
; After the division process EAX will contain the quotient
; And EDX will contain the remainder, thus the 0's we filled
; it with will be overwritten with the remainder
cmp EDX, 0 ; Compare EDX (remainder) to 0
; Since the 0's were overwritten with the remainder after the division
; the compare will see the new remainder NOT the 0's that was in it before!!
jne findTheGCD ; UNTIL ( remainder == 0 )
;************************ PRINT THE GCD TO SCREEN ******************
dtoa gcdResult, EBX ; convert to ASCII characters
output resultLbl, resultLb2 ; output label and gcd string
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END