Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio x64程序集新手,不确定为什么用户输入仍然为0_Visual Studio_Loops_Assembly_X86 64_Masm - Fatal编程技术网

Visual studio x64程序集新手,不确定为什么用户输入仍然为0

Visual studio x64程序集新手,不确定为什么用户输入仍然为0,visual-studio,loops,assembly,x86-64,masm,Visual Studio,Loops,Assembly,X86 64,Masm,我的程序应该读取一组有符号整数,并显示输入的最大值和最小值。当输入后输入零时,它将打印,但如果输入的第一个值为0,则程序必须立即结束而不显示任何内容。我一直在琢磨如何存储用户输入的所有数字,因为我测试打印时它只是0,所以我假设这些值被破坏了。我还没有找到比较数字的循环,因为我已经花了很长一段时间思考这个部分,并找到了一个让哨兵工作的拙劣方法,但我会去做的。有人能告诉我我做错了什么吗 输出: Enter a series of numbers: 100 250 500 0 Largest: 0 S

我的程序应该读取一组有符号整数,并显示输入的最大值和最小值。当输入后输入零时,它将打印,但如果输入的第一个值为0,则程序必须立即结束而不显示任何内容。我一直在琢磨如何存储用户输入的所有数字,因为我测试打印时它只是0,所以我假设这些值被破坏了。我还没有找到比较数字的循环,因为我已经花了很长一段时间思考这个部分,并找到了一个让哨兵工作的拙劣方法,但我会去做的。有人能告诉我我做错了什么吗

输出:

Enter a series of numbers:
100
250
500
0
Largest: 0
Smallest: 0
源代码:


extrn DisplayString:          PROTO
extrn DisplayNewline:         PROTO
extrn ReadInt:                PROTO
extrn DisplayInt:           PROTO
extrn ExitProcess:            PROTO

.data
msg1            byte    'Enter a series of numbers: ', 0
largestMsg      byte    'Largest: ',0
smallestMsg     byte    'Smallest: ',0

.data?
input               byte    ?
smallest            word    ?
largest             word    ?           
numsEntered         byte    ?


.code

main        PROC

                ;Prepare for stacks
                sub     rsp, 32                 ;reserve shadow space
                push    rbp                     ;save non-volatile base pointer
                mov     rbp, rsp                ;make frame pointer for direct access
                mov     rcx, 100                ;get address of request
                lea     rbx, numsEntered        ;get address of array

                ;Print prompt
                lea     rcx, msg1               ;store in address the prompt
                call    DisplayString           ;print message
                call    DisplayNewline          ;print new line

                ;Get First input and compare to sentinel
                lea     rcx, input              ;point input to address
                call    readInt                 ;read user input
                push    rcx
                mov     r12b, input             ;store input in register
                cmp     r12b, 0                 ;compare input to sentinal
                je      Continue                ;if input = to sentinal exit code
                jg      asknum                  ;if input greater than sentinal jp to loop


asknum:         ;Read and compare user input until they enter 0
                lea     rcx, input              ;point input to address
                call    readInt                 ;read user input
                mov     r12b, input             ;store input in register
                cmp     input, 0                ;compare input to sentinal
                je      PrintLargest            ;if user types sentinal after inputs, jp to print largest num

                loop    asknum                  ;loop for user input

PrintLargest:
            lea     rcx, largestMsg             ;point to prompt address
            call    DisplayString               ;print prompt largestMsg
            lea     rcx, largest                ;point largest integer to address
            call    DisplayInt                  ;print largest integer
            call    DisplayNewline              ;print new line
            jp      PrintSmallest               ;jump to calculate smallest integer

PrintSmallest:
            ;after printing largest, print the smallest
            lea     rcx, smallestMsg            ;point to prompt address
            call    DisplayString               ;print prompt smallestMsg
            lea     rcx, smallest               ;point smallest integer to address
            call    DisplayInt                  ;print smallest integer 
            jp      Continue                    ;jump to exit code

Continue:
        pop     rbp                     ;clear stack
        add     rsp, 32                 ;restore shadow space
        call    ExitProcess             ;exit code

main        ENDP
END

Output:



代码看起来不像C++。是汇编吗?是的,代码是汇编的,并链接到C++文件,以获得打印的外部函数。[因为它不是很重要,我将去掉C++标签]:你确信你的<代码> DePositIt/Cuff>函数取一个整数(用指针ARG),而不是值吗?如果没有,则执行
mov
加载,而不是
lea
加载地址。(可能不是问题,只是我注意到的第一件奇怪的事情。)另外,让
readInt
在RAX中返回一个值将是一个更好的设计,尽管传递一个输出参数指针可以让这个函数将该值传递给scanf。我只是在.cpp文件中进行了双重检查,它确实通过引用将整数作为外部“C”void DisplayInt(int*pi)的值//dword{printf(“%d”,*pi);//cout