有很多方法可以回答这个问题,而不是你更具体(架构,系统调用或libc,gas或nasm,输出格式等),但这里是一种方式(x86,libc,nasm)
bits 32
section .text
extern printf
global main
main:
fldpi ; load pi onto FPU stack
sub esp, 8 ; make space on CPU stack
fstp qword [esp] ; pop from FPU stack and store on CPU stack (parameter 2 of printf)
push format ; stack the format string (parameter 1 of printf)
call printf
add esp,12 ; restore stack (4 btyes address + 8 bytes float)
xor eax,eax ; set eax (return value) to 0
ret ; return to libc
section .data
format: db "%.20g",10,0
Run Code Online (Sandbox Code Playgroud)
输出:3.141592653589793116