⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quad.asm

📁 关于linux环境下的nasm代码的生成和使用
💻 ASM
字号:
;; file: quad.asm; function quadratic; finds solutions to the quadratic equation: ;       a*x^2 + b*x + c = 0; C prototype:;   int quadratic( double a, double b, double c,;                  double * root1, double *root2 ); Parameters:;   a, b, c - coefficients of powers of quadratic equation (see above);   root1   - pointer to double to store first root in;   root2   - pointer to double to store second root in; Return value:;   returns 1 if real roots found, else 0%define a               qword [ebp+8]%define b               qword [ebp+16]%define c               qword [ebp+24]%define root1           dword [ebp+32]%define root2           dword [ebp+36]%define disc            qword [ebp-8]%define one_over_2a     qword [ebp-16]segment .dataMinusFour       dw      -4segment .bss segment .text        global  quadraticquadratic:        push    ebp        mov     ebp, esp        sub     esp, 16         ; allocate 2 doubles (disc & one_over_2a)        push    ebx             ; must save original ebx        fild    word [MinusFour]; stack -4        fld     a               ; stack: a, -4        fld     c               ; stack: c, a, -4        fmulp   st1             ; stack: a*c, -4        fmulp   st1             ; stack: -4*a*c        fld     b        fld     b               ; stack: b, b, -4*a*c        fmulp   st1             ; stack: b*b, -4*a*c        faddp   st1             ; stack: b*b - 4*a*c        ftst                    ; test with 0        fstsw   ax        sahf        jb      no_real_solutions ; if disc < 0, no real solutions        fsqrt                   ; stack: sqrt(b*b - 4*a*c)        fstp    disc            ; store and pop stack        fld1                    ; stack: 1.0        fld     a               ; stack: a, 1.0        fscale                  ; stack: a * 2^(1.0) = 2*a, 1        fdivp   st1             ; stack: 1/(2*a)        fst     one_over_2a     ; stack: 1/(2*a)        fld     b               ; stack: b, 1/(2*a)        fld     disc            ; stack: disc, b, 1/(2*a)        fsubrp  st1             ; stack: disc - b, 1/(2*a)        fmulp   st1             ; stack: (-b + disc)/(2*a)        mov     ebx, root1        fstp    qword [ebx]     ; store in *root1        fld     b               ; stack: b        fld     disc            ; stack: disc, b        fchs                    ; stack: -disc, b        fsubrp  st1             ; stack: -disc - b        fmul    one_over_2a     ; stack: (-b - disc)/(2*a)        mov     ebx, root2        fstp    qword [ebx]     ; store in *root2        mov     eax, 1          ; return value is 1        jmp     short quitno_real_solutions:        ffree   st0             ; dump disc off stack        mov     eax, 0          ; return value is 0quit:        pop     ebx        mov     esp, ebp        pop     ebp        ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -