0

我正在寻找总和用户输入的整数。我通过使用比较和跳转设置了一个循环。这是我接近它的方式,但我无法让它工作。

;====Display message asking user========
mov         qword rdi, stringformat                                 
mov         qword rsi, promptfloatnumber                                      
mov         qword rax, 0                                            
call        printf            

;====Input number========
push        qword 0                                                
mov         qword  rdi, floatinputformat                            
mov         qword  rsi, rsp                                         
mov         qword  rax, 0                                           
call        scanf                                            

pop         r14

;===== Copy input to SSE======
push        r14                                              
movsd       xmm1, [rsp]                                      
pop         rax

;=== Keeps a total count throughout the loops? =====                                      
addsd       xmm0,xmm1        ;xmm0 = xmm0 + xmm1

;Then it jumps back up if user wants to input more values

那我只需要显示 xmm0 总对吗?我不知道该怎么做。我尝试过这样的事情。

mov         rdi, formatfloatdecimaloutput              
mov qword   rax, 1                                           
call        printf                                           
4

1 回答 1

1

这就是clang我的 OS X 机器上的操作方式——为清楚起见进行了注释:

# this is the constant '(double)2.5'
LCPI0_0:
    .quad   4612811918334230528     ## double 2.500000e+00
                                    ##  (0x4004000000000000)

    leaq    L_.str(%rip), %rdi      # arg1 = format string address
    movsd   LCPI0_0(%rip), %xmm0    # float arg2 = 2.5
    movb    $1, %al                 # number of floating-point arguments
    callq   _printf


    .section    __TEXT,__cstring,cstring_literals
L_.str:
    .asciz   "%f\n" # here's the format string
于 2013-09-08T13:52:55.783 回答