Search the Community
Showing results for tags 'ecuatie'.
-
;////////////////////////////////////////////////////////////////! ; ; Eq_G2 v.3 by cybervu - RSTForums.com ; ;////////////////////////////////////////////////////////////////| ; ; Formula: ax^2 + bx + c = 0 ; Radacini: x(1,2) = (-b +/- sqrt(b^2 - 4*a*c)) / (2*a) ; ;////////////////////////////////////////////////////////////////| ; ; x86 CPU instruction set ; ; finit Initialize floating point processor ; fld Floating point load ; fld1 Push +1.0 onto the FPU register stack. ; fldz Push +0.0 onto the FPU register stack. ; fdiv Divide ; fdivp Divide and pop ; fadd Add ; fmul Multiply ; fldz Load 0.0 onto stack ; fcom Compare ; fcomp Compare and pop ; fsqrt Square root ; fchs Change sign ; fsubr Reverse subtract ; fsubrp Reverse subtract and pop ; fst Store ; fstp Store and pop ; fstsw Store status word ; sahf Store AH into flags ; ;/////////////////////////////////////////////////////////////////////////////' .686 ; 32 bit code .model flat, stdcall ; 32 bit memory model option casemap :none ; case sensitive include \masm32\include\masm32.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\msvcrt.inc includelib \masm32\lib\masm32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\msvcrt.lib include \masm32\macros\macros.asm .Data xA Real10 ? xB Real10 ? xC Real10 ? x1 Real10 ? x2 Real10 ? .Code start: Call Main exit ; ------------------------------------------------------------------------- InputR10 Proc ptr10:Ptr Real10 ; citeste o valoare reala (float) // crt_scanf() LOCAL r8:Real8 invoke crt_scanf, SADD("%lf"), ADDR r8 mov eax, ptr10 finit fld r8 fstp Real10 PTR [eax] Ret InputR10 EndP ; ------------------------------------------------------------------------- satan Proto:Real10, :Real10, :Real10 Main Proc print "A=" Invoke InputR10, Addr xA ; input A print "B=" Invoke InputR10, Addr xB ; input B print "C=" Invoke InputR10, Addr xC ; input C Invoke satan, xA, xB, xC ; calcule Ffree st(0) ; goleste stiva Ffree st(1) ; Ffree st(2) ; print chr$(13, 10) print "cybervu - RSTForums.com" call wait_key ; "Press any key to continue..." Ret Main EndP ; ------------------------------------------------------------------------- satan Proc A_:Real10, B_:Real10, C_:Real10 ; b*b si pune in stiva finit ; init fld B_ ; incarca b fld st ; b fmul ; st(0) = b*b = b^2 ; 4*a*c fld1 ; 1 fld1 ; 1 fadd ; st(0) = 1 + 1 = 2 fld st ; 2 fadd ; st(0) = 2 + 2 = 4 fld A_ ; incarca a fld C_ ; incarca c fmul ; fmul ; st(0) = 4*a*c ; st(1) = b^2 fsub ; st(0) = st(1) - st(0) // = delta ; delta (?) 0 : jmp fldz ; incarca 0 fcomp st(1) ; compara st(1)=0 cu st(0) = ((b^2)-(4*a*c)) // = delta fstsw ax ; salveaza sahf ; jbe delta_ok ; delta >= 0 jmp delta_negativ ; -> "nu are radacini reale" delta_ok: fsqrt ; extrage radical fld st ; copie fld B_ ; incarca b fchs ; schimba semnul // -b fadd st(1),st ; st(1) = [-b] + [sqrt(delta)] fsubrp st(2),st ; st(0) = [-b] + [sqrt(delta)] si st(1) = [-b] - [sqrt(delta)] fld A_ ; incarca a fld1 ; incarca 1 fld1 ; incarca 1 fadd ; 1+1= 2 fmul ; st(0) = 2*a fld st ; fdivp st(2),st ; imparte si pop fdivp st(2),st ; -> st(0) = (((- + [sqrt(delta)])/2a) si st(1) = (((- - [sqrt(delta)])/2a) fstp x1 ; salveaza in x1, pop fstp x2 ; salveaza in x2 print chr$(13, 10) print "x1=" print real10$ (x1) ; print x1 print chr$(13, 10) print "x2=" print real10$ (x2) ; print x2 print chr$(13, 10) jmp gata delta_negativ: ; delta < 0 print chr$(13, 10) print "nu are solutii reale" print chr$(13, 10) gata: Ret satan EndP End start Resurse: X86 Instruction Listings - Wiki Art Of Assembly