Hello,

im trying to solve the following equation:

3x?-7x+2=0

a=3, b=-7 e c=2

(-7)?-4.3.2

49-24 = 25

;eax=3

;edx=-7

;ecx=2

;ebx=4

im putting this in a proc cause i never did it before and i'd like to learn

solve proc near

xor eax, eax

xor edx, edx

mov ebx, 4

mov eax, 3

mov ecx, 2

imul eax, ecx

imul eax, ebx ; eax = 24

mov edx, -7 ; (-7)? part, idont get -49 as i should :/ -7*2=-49, any idea ?

imul edx, 2

; here im gonna do the subtraction

ret

solve endp

if anyone could help, thanks a lot.

ps : i dont understand fpu nor mmx but if u'd like to show me how to do on these n\p i'll learn soon :)

im trying to solve the following equation:

3x?-7x+2=0

a=3, b=-7 e c=2

(-7)?-4.3.2

49-24 = 25

;eax=3

;edx=-7

;ecx=2

;ebx=4

im putting this in a proc cause i never did it before and i'd like to learn

solve proc near

xor eax, eax

xor edx, edx

mov ebx, 4

mov eax, 3

mov ecx, 2

imul eax, ecx

imul eax, ebx ; eax = 24

mov edx, -7 ; (-7)? part, idont get -49 as i should :/ -7*2=-49, any idea ?

imul edx, 2

; here im gonna do the subtraction

ret

solve endp

if anyone could help, thanks a lot.

ps : i dont understand fpu nor mmx but if u'd like to show me how to do on these n\p i'll learn soon :)

Correct me if, I'm wrong, are you solving for x?

if it is the answer is 2.

if it is the answer is 2.

I don't understand what is in eqution.

Could anybody to be so kind translating it in words.

Could anybody to be so kind translating it in words.

Hi,

im using Bhaskara formula, i dont know the name of this equation in english, i guess its something like "second xxx equation"

3x?-7x+2=0

a=3, b=-7 e c=2

hope things are clear now :)

im using Bhaskara formula, i dont know the name of this equation in english, i guess its something like "second xxx equation"

3x?-7x+2=0

a=3, b=-7 e c=2

**delta**= (-7)?-4.3.2 = 49-24 = 25hope things are clear now :)

hmm looks like the quadratic formula: ax^2 + bx + c = 0

In this equation there are 2 answers:

a=3, b=-7

I'm not sure what the e meant. Tell me if I'm wrong.

It's very hard to make an FPU code out of it since this has 2 equations for the final answer. :confused: choose your flavor of the 2

ok for the first one(Assuming NumberOne == 1...)?

fild NumberOne

fidiv a

fstp Result

```
```

-> 3x^2 + (-7x) + 2 = 0

-> 3x^2 - 7x + 2 = 0

-> (3x - 1)(x - 2)

In this equation there are 2 answers:

```
```

-> 3x - 1 = 0 -> x - 2 = 0

-> 3x = 1 -> x = 2

-> x = 1/3

a=3, b=-7

**e**c=2

I'm not sure what the e meant. Tell me if I'm wrong.

It's very hard to make an FPU code out of it since this has 2 equations for the final answer. :confused: choose your flavor of the 2

ok for the first one(Assuming NumberOne == 1...)?

fild NumberOne

fidiv a

fstp Result

(-7)? part

(-7)? part means square of (-7) ?

(-7) multiplies (- 7)?

then

mov eax,-7

imul eax

-7*2=-49

if you - 7 ^ 2 (-7 in power of 2) then it equals 49 ,not - 49.

So you calculating delta, not x, don't you?

umberg6007, sorry, e means and, i got it from a book and forgot to translate.

The Svin, my aim was to find delta i could do it

solve proc near

xor eax, eax

xor edx, edx

mov ebx, 4

mov eax, 3

mov ecx, 2

imul eax, ecx

imul eax, ebx

mov edi, eax

mov eax,-7

imul eax

sub eax, edi

; eax = delta

ret

solve endp

i know this isnt optimized, i've no idea how to optimize, well im new to win32asm and i sux at math, but i found it challenging trying to do some math exercises like this one in asm.

thanks to all.

The Svin, my aim was to find delta i could do it

solve proc near

xor eax, eax

xor edx, edx

mov ebx, 4

mov eax, 3

mov ecx, 2

imul eax, ecx

imul eax, ebx

mov edi, eax

mov eax,-7

imul eax

sub eax, edi

; eax = delta

ret

solve endp

i know this isnt optimized, i've no idea how to optimize, well im new to win32asm and i sux at math, but i found it challenging trying to do some math exercises like this one in asm.

thanks to all.

ax? + bx + c = 0,

http://www.purplemath.com/modules/quadform.htm

This PROC is for (b? - 4ac) part of the above.

edit: removed picture, replaced by link on author request.

http://www.purplemath.com/modules/quadform.htm

This PROC is for (b? - 4ac) part of the above.

edit: removed picture, replaced by link on author request.

bitRAKE :)

i knew u would POP

i wonder if the proc can be optimized ?

or a way i can pass the parameters to the call like

push a

push b

push c

call solve

:stupid:

dunno why i added this image but i identified myself with it :P

i knew u would POP

i wonder if the proc can be optimized ?

or a way i can pass the parameters to the call like

push a

push b

push c

call solve

:stupid:

dunno why i added this image but i identified myself with it :P

Thanks, Rake.

Now I finally get it :)

Now I finally get it :)

FWIW, there is a proc to solve quadratics in the FPU chapter of the MASM6.1 manual.

the one above i gave is the quadratic equation not the quadratic formula :)

for the squareRoot(b^2 - 4ac):

multiply b with -1.

now we must choose whether if we should go adding or subtracting

then we divide by 2a

if you go with subtracting you should have an answer of 0.333 . If addition it should be 2. Here's an attached program to do just that. Though this one is not well optimized, it should do the job for you.

Happy Coding!!!

for the squareRoot(b^2 - 4ac):

```
```

[size=9]

finit

fld bV

fmul bV

fld four

fmul aV

fmul cV

fsub

fsqrt

fstp result

;The result should be 5

[/size]

multiply b with -1.

```
```

[size=9]

fld bV

fmul negOne

fstp bV

[/size]

now we must choose whether if we should go adding or subtracting

```
```

[size=9]

;This is adding

fld bV

fadd result

fstp result

[/size]

```
```

[size=9]

;This is subtracting

fld bV

fsub result

fstp result

[/size]

then we divide by 2a

```
```

[size=9]

fld result

fld two

fmul aV

fdiv

fstp result

[/size]

if you go with subtracting you should have an answer of 0.333 . If addition it should be 2. Here's an attached program to do just that. Though this one is not well optimized, it should do the job for you.

Happy Coding!!!

thanks for the code, i was just playing a little.

Just last week i wrote a small program to find the roots of a quadratic. I've attached it, but it's not pretty.

Just note that it's a console app, so either:

- use the RadAsm project file i included

- build it with the makefile included, 'makefile quad'

- build it on your own

I'll repeat it's not very pretty, but it does account for all three possible cases for the roots.

malone

Just note that it's a console app, so either:

- use the RadAsm project file i included

- build it with the makefile included, 'makefile quad'

- build it on your own

I'll repeat it's not very pretty, but it does account for all three possible cases for the roots.

malone

Come on

**malone**, you must be joking! That code is fairly neat, and easily read. I like the constructive use of macros - kind of self-documenting. Good work!Thanks for the encouragement bitRake :)

malone

malone