Assembly 汇编语言:两个提示用户输入(混合字符和int)

Assembly 汇编语言:两个提示用户输入(混合字符和int),assembly,masm,irvine32,Assembly,Masm,Irvine32,我是汇编编程新手,需要帮助理解和修复一些我一直在努力解决的代码: 我想提供用户输入: 提示1:输入目的地 读取值 提示2:输入目的地 读取值 显示距离和目的地 我在x64硬件上使用VS2012和Irvine32库。我编译为x32 问题 代码编译并生成。但输出不正确。第一个提示仅在没有输入的情况下显示。显示第二个提示“距离”,允许输入。如果我将第一个提示更改为“readInt”而不是“readString”,则两个提示中都会出现提示,但会出现“Invalid Integer”错误。为什么会这样?如

我是汇编编程新手,需要帮助理解和修复一些我一直在努力解决的代码: 我想提供用户输入:

提示1:输入目的地 读取值 提示2:输入目的地 读取值 显示距离和目的地

我在x64硬件上使用VS2012和Irvine32库。我编译为x32

问题 代码编译并生成。但输出不正确。第一个提示仅在没有输入的情况下显示。显示第二个提示“距离”,允许输入。如果我将第一个提示更改为“readInt”而不是“readString”,则两个提示中都会出现提示,但会出现“Invalid Integer”错误。为什么会这样?如何解决此问题并显示输入值

我的代码

INCLUDE irvine32.inc

;*************************************************************************      
.data
    queryDest   byte   "Destination", 0
    queryDist   byte   "Distance", 0

    destination       dword   ?
    distance       dword   ?

.code
 main proc
        call clrscr

        mov edx, offset queryDest
        call writeString
        call readString
        mov destination, eax

        call crlf
        mov edx, offset queryDist
        call writeString
        call readInt
        mov distance, eax

        call crlf
        Call WaitMsg        ;causes a wait for a key to be pressed
        exit
main endp
end main
电流输出

目的地

距离50


按任意键继续…

未测试,因为my VS 2012拒绝工作(正在工作)。您的主要问题是
destination
必须是字符串,而不是数字:

INCLUDE irvine32.inc

;*************************************************************************      
.data
    queryDest   byte   "Destination=", 0
    queryDist   byte   "Distance=", 0

    destination byte   "                     " ; LENGTH 21.
    distance    dword   ?

.code
 main proc
        call clrscr
 ;READ DESTINATION.    
        mov edx, offset queryDest
        call writeString             ;DISPLAY MESSAGE.

        mov edx, offset destination  ;STORE STRING HERE (ZERO TERMINATED).
        mov ecx, 20                  ;MAX CHARS TO READ.
        call readString              ;STORES STRING WHERE EDX POINTS.

        call crlf
 ;READ DISTANCE.
        mov edx, offset queryDist
        call writeString             ;DISPLAY MESSAGE.
        call readInt
        mov distance, eax

 ;DISPLAY DESTINATION AND DISTANCE.
        call crlf
        call crlf
        mov edx, offset destination   ;EDX POINTS TO STRING TO DISPLAY.
        call writeString              ;DISPLAY DESTINATION.
        call crlf
        mov eax, distance             ;NUMBER TO DISPLAY.
        call writeInt                 ;DISPLAY DISTANCE.

        call crlf
        Call WaitMsg        ;causes a wait for a key to be pressed
        exit
main endp
end main

未测试,因为我的VS 2012拒绝工作(正在工作)。您的主要问题是
destination
必须是字符串,而不是数字:

INCLUDE irvine32.inc

;*************************************************************************      
.data
    queryDest   byte   "Destination=", 0
    queryDist   byte   "Distance=", 0

    destination byte   "                     " ; LENGTH 21.
    distance    dword   ?

.code
 main proc
        call clrscr
 ;READ DESTINATION.    
        mov edx, offset queryDest
        call writeString             ;DISPLAY MESSAGE.

        mov edx, offset destination  ;STORE STRING HERE (ZERO TERMINATED).
        mov ecx, 20                  ;MAX CHARS TO READ.
        call readString              ;STORES STRING WHERE EDX POINTS.

        call crlf
 ;READ DISTANCE.
        mov edx, offset queryDist
        call writeString             ;DISPLAY MESSAGE.
        call readInt
        mov distance, eax

 ;DISPLAY DESTINATION AND DISTANCE.
        call crlf
        call crlf
        mov edx, offset destination   ;EDX POINTS TO STRING TO DISPLAY.
        call writeString              ;DISPLAY DESTINATION.
        call crlf
        mov eax, distance             ;NUMBER TO DISPLAY.
        call writeInt                 ;DISPLAY DISTANCE.

        call crlf
        Call WaitMsg        ;causes a wait for a key to be pressed
        exit
main endp
end main

@JoseManuelAbarcaRodríguez我对Aseembly是新手。“我正在努力理解你的建议。”约瑟曼纽拉巴卡罗德里格斯我对阿塞姆布里是新手。我试图理解您的建议。它抱怨“目标字节”“//LENGTH 21”上的“error A2084:常量值太大”。这非常有用。谢谢@jose@Sylvester,抱歉,我一直在使用PHP,其中的注释是
//
(oops!)。它抱怨“目标字节”“//LENGTH 21”上的“错误A2084:常量值太大”。非常有用。谢谢@jose@Sylvester,抱歉,我一直在使用PHP,其中的注释是
/
(oops!)。