输入浮点数并将其输出回装配中的屏幕?

时间:2013-02-16 00:20:55

标签: assembly input output

我一直致力于这项任务,并且无法通过其中一个部分,这应该很简单。我和我的教授一直在讨论它,但他也无法弄明白......我希望能在这里得到一些帮助。我只想输入一个数字,将其推入st0,然后弹出并将其存储到total_mean中。出于测试目的,我在开头注释掉了代码。

extern printf
extern scanf

segment .data
    prompt_name db "Please enter you name: ", 0
    input_name db "%s %s",0
    ready db "Please have your numberic data ready",10,0
    get_num db "Enter a floating number: ",0
    stringdata db "%s",0

    namedata db "%s ",0
    display_name db "%s",10,0
    floatdata db "%Lf",0
    ask db "Are there more numbers (Y or N)? ", 0

    mean db "The mean of these %d values is %Lf",10,0
    largest db "the largest value is %Lf",10,0
    smallest db "the smallest value is %Lf",10,0

    more db "Do you have more data to analyze (Y or N)? ",0

    bye db "Thank you %s. I hope you enjoyed this program.",10,0


segment .bss
    user_float: resq 1
    large: resq 1
    small: resq 1
    total_mean: resq 2
    first_name: resb 32
    last_name: resq 32

segment .text

    global start_loop

start_loop:

;   mov rax,0
;   mov rdi, stringdata
;   mov rsi, prompt_name
;   call printf
;
;   mov qword rax, 0
;   mov rdi, input_name
;   mov rsi, first_name
;   mov rdx, last_name
;   call scanf
;
;   mov rax, 0
;   mov rdi, namedata
;   mov rsi, first_name
;   call printf
;
;   mov rax, 0
;   mov rdi, display_name
;   mov rsi, last_name
;   call printf
;
;   mov rax, 0
;   mov rdi, stringdata
;   mov rsi, ready
;   call printf
;
;   mov rax, 0
;   mov rdi, stringdata
;   mov rsi, get_num
;   call printf

    mov qword rax, 0
    push qword 0
    push qword 0
    mov rdi, floatdata
    mov rsi, rsp
    call scanf

    push qword 0
    push qword 0

    fld tword [rsp]
    fmul

    fstp tword [total_mean]

    mov qword rax, 0
    mov qword rax,0
    mov rdi, floatdata
    mov rsi, total_mean
    call printf

    pop rax
    pop rax
    pop rax
    pop rax

ret

它只是下半部分我试图从键盘输入我有问题。当我输入一个数字,例如12.0,并显示它时,它显示0.00000。有人可以帮我找到解决方案吗?

1 个答案:

答案 0 :(得分:0)

在x86-64中,您在double寄存器中传递XMM个参数,而不是在80387 fpu堆栈中传递。当您在这里使用SystemV ABI时(通过printfscanf调用可见),只需将第一个double参数放到XMM0,将第二个XMM1放入XMM7 {{1}}等等(最多{{1}})。