How to write a several values on the screen using C printf function?

梦想与她 提交于 2020-05-24 05:34:12

问题


I have a program that counts root of quadratic equation. And I have a problem with printing the results on the screen, because I can print only one value.

This is my code below, could you please tell me what should I do to pass two result to expression "x1 = ... ".

[bits 32]

call getaddr

format db "x1 = %lf, x2 = %lf", 0xA, 0
offset equ $ - format
a      dq 1.0 ;
b      dq -11.0
c      dq 28.0
minusfour  dq -4.0

getaddr:

finit

mov eax, [esp]
lea eax, [eax+offset] ; eax = a
mov edx, [esp]
lea edx, [edx+offset+8] ; edx = b
mov ecx, [esp]
lea ecx, [ecx+offset+16] ; ecx = c
mov esi, [esp]
lea esi, [esi+offset+24] ; edi = minusfour

fld qword [esi] ; st: -4
fld qword[eax] ; st: a, -4
fld qword[ecx] ; st: c, a, -4
fmulp st1 ; st: a*c, -4
fmulp st1 ; st: -4*a*c
fld qword[edx] ; st: b, -4*a*c
fld qword[edx] ; st: b, b, -4*a*c
fmulp st1 ; st: b*b, -4*c*a
fadd st1 ; st: b*b - 4*a*c


fsqrt ; root of delta
fstp qword [ecx]; ecx = root of delta => st: empty
fld qword[eax]; st: a
fld qword[eax]; st: a, a
faddp st1; st: 2a
fstp qword[eax] ; eax = 2a => st: empty
fld qword[edx]; st: b
fchs  ; st: -b
fld qword[ecx]; st: -b, delta

    ;x1
    fsubp st1; st: -b-delta
    fld qword[eax]; st: -delta-b, 2a
    fdivp st1; st: (-delta-b)/2a
    lea eax, [esp+4]
    fstp qword[eax]
    call[ebx+3*4] ; start print function
    add esp, 3*4

    ;x2     
    faddp st1; st: -b+delta
    fld qword[eax]; st: delta-b, 2a
    fdivp st1 ; (delta-b)/2a
    lea edx, [esp+8]
    fstp qword[edx]
    call[ebx+3*4] ; start print function
    add esp, 3*4

Maybe there is another way to write it on the screen, I will be grateful for any help

来源:https://stackoverflow.com/questions/61942754/how-to-write-a-several-values-on-the-screen-using-c-printf-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!