News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

The task to the school

Started by dawidekz, February 01, 2009, 06:37:24 PM

Previous topic - Next topic

dawidekz

Hi,
I'm novice in assembler. Programme which I need to do to the school will have to count the Quadratic Square. The programme has to use functions winapi. (had to be realized in the window).
I ask for the help very much.

P.S I apologize for my English... :red

d0d0

howdy!

well, you could start by downloading and installing the MASM32 package if you haven't already done that. There some tutorials that come with it. Once you have an idea on how and what to do, you can post your code here and the community will help you.

Otherwise it would be spoon feeding you and doing the work for you.

Do you intend to learn asm or you're only in it for the school project?

dawidekz

I already installed the packet MASM and looked through various examples. I bought two books on the subject Win32Asm, but to learn in the week heavily.
I would like to use the example from MASM / examples (attach file)
I do not know as to pass on parameters from EDIT and how to make mathematical calculations

In this moment this programme, work and the end of the school he does not allow me to deepen knowledge from this subject :{

[attachment deleted by admin]

d0d0

no problem. do you mean solving quadratic equations using the formula :

x1, x2 = −b ± √b2 − 4ac / 2a

dawidekz

#4
I do not know as to apply this the formula in the code

d0d0

try this:

This should get you going.The example I found in Paul Carter's book on pg 129 (PC Assembly - available online).  The original version was in NASM syntax. Please note this is a quick conversion and I haven't tested it. I'm sure the experts around will help :green2

va textequ <dword ptr [ebp+8]> ;a
vb textequ <dword ptr [ebp+12]> ;b
vc textequ <dword ptr [ebp+16]> ;c
disc         textequ <dword ptr [ebp-4]>
one_over_2a textequ <dword ptr [ebp-8]>

.data
x1 dd ?
x2 dd ?
minus4 dd -4

quadratic PROC
push ebp
mov ebp, esp
sub esp, 8
push ebx

fild minus4
fld va
fld vc
fmulp st(1), st
fmulp st(1), st
fld vb
fld vb
fmulp st(1), st
faddp st(1), st
ftst
fstsw ax
sahf
jb no_real_sols
fsqrt
fstp disc
fld1
fld va
fscale
fdivp st(1), st
fst one_over_2a
fld vb
fld disc
fsubrp st(1), st
fmulp st(1), st
lea ebx, x1
fstp dword ptr [ebx]
fld vb
fld disc
fchs
fsubrp st(1), st
fmul one_over_2a
lea ebx, x2
fstp dword ptr [ebx]
mov eax, 1
jmp quit

no_real_sols:
ffree st
mov eax, 0

quit:
pop ebx
mov esp, ebp
pop ebp
ret

quadratic ENDP



dawidekz

And there is the problem here.. I do not know as to add this code to my programme. Inserting the code itself to MASM gives a lot of mistakes. I am too weak to put this together in the whole :(

I see this heavily.. :/

Farabi

Quote from: dawidekz on February 04, 2009, 07:09:56 PM
And there is the problem here.. I do not know as to add this code to my programme. Inserting the code itself to MASM gives a lot of mistakes. I am too weak to put this together in the whole :(

I see this heavily.. :/

What is the error message?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

raymond

This would be my take in MASM syntax. A lot more readable. This one assumes that the coefficients a, b and c are all signed 32-bit integers passed on the stack as parameters. A similar procedure could be written for REAL coefficients by changing the fixxx instructions by the fxxx variety.

Results are returned as 32-bit floats in the uninitialized global data section. They could be returned as other data types with minor modifications to the code. The procedure is also designed for Pentium4 and up (I don't think many functional P3's remain in existance).

QuadRoots proc public a:DWORD, b:DWORD, c:DWORD
; to compute the roots of the quadratic equation ax^2+bx+c=0
.data?
   x1    REAL4  ?
   x2    REAL4  ?

.code
   fild a          ;a
   fld  st         ;a   a
   fadd st(1),st   ;a   2a
   fimul c         ;ac   2a
   fadd st,st      ;2ac   2a
   fadd st,st      ;4ac   2a
   fild b          ;b   4ac   2a
   fmul st,st      ;b^2   4ac   2a
   fsubr           ;(b^2-4ac)   2a
   fldz            ;0   (b^2-4ac)   2a  
   fcomip st,st(1) ;(b^2-4ac)   2a
   ja   no_solution
   fsqrt           ;sqrt(b^2-4ac)   2a
   fld  st         ;sqrt(b^2-4ac)   sqrt(b^2-4ac)   2a
   fisub b         ;-b+sqrt(b^2-4ac)   sqrt(b^2-4ac)   2a
   fdiv st,st(2)   ;x1   sqrt(b^2-4ac)   2a
   fstp x1         ;sqrt(b^2-4ac)   2a
   fchs            ;-sqrt(b^2-4ac)   2a
   fisub b         ;-b-sqrt(b^2-4ac)   2a
   fdivr           ;x2
   fstp x2
   mov  eax,1      ;success code
   jmp  eXit
no_solution:
   fstp st
   fstp st         ;clean FPU
   xor  eax,eax    ;failure code
eXit:
   ret
QuadRoots endp
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dawidekz

I have Athlon 64 :/
I have such error: H:\masm32\examples\oolo.asm(18) : error A2085: instruction or register not accepted in current CPU

MichaelW

Try posting your source, otherwise we are just guessing at what the problem might be.
eschew obfuscation

d0d0

MichaelW

I think he posted the example he wanted to use from masm - first.zip (attached to 3rd post). I thought he wanted just a proc to calculate quad roots. Raymond posted a complete function to do that.

MichaelW

The source in first.zip assembles and links with no problems, and adding FPU instructions does not change this, so I assume it is not the source with the problem.
eschew obfuscation

kromag

dawidekz,

    You could try your luck with http://win32assembly.online.fr/files/Exagone-Tuts.zip

Tutorial by Exagone on the basics!
---
William

dawidekz

The problem is such... I don't know, how i can join first.zip with procedure... :/