我一直试图在汇编程序中与Windows中的标准C库进行交互,但我遇到了麻烦。出于某种原因,我不能让printf接受浮点变量,所以这里有些不对。
这是我可以创建的最短程序来演示问题。我收录的评论解释了我对应该发生的事情的理解。
由于
;
; Hello64.asm
; A simple program to print a floating point number in windows
;
; assemble: nasm float64.asm -f win64
; link: golink /console /entry main float64.obj MSVCRT.dll
;
; tell assembler to generate 64-bit code
;
bits 64
; data segment
section .data use64
pi dq 3.14159
textformat: db "hello, %lf!",0x0a, 0x00 ; friendly greeting
; set up the .text segment for the code
section .text use64
; global main is the entry point
global main
; note that there is no _ before printf here, unlike in OS X
extern printf
main:
mov rcx, textformat
movq xmm0, qword [pi]
mov rax, 1 ; need to tell printf how many floats
call printf
; note next step - this puts a zero in rax
xor rax,rax
ret ; this returns to the OS based on how Windows calls programs.
; this return causes a delay then the program exits.
答案 0 :(得分:4)
您设法混合了microsoft和sysv约定。正确的方法是:
p = &(d.elmts[i]);
根据MSDN,使用varargs:
仅对于浮点值,如果被调用者期望整数寄存器中的值,则整数和浮点寄存器都将包含浮点值。