flat assembler
Message board for the users of flat assembler.

Index > Main > 3D Problem Solved

Author
Thread Post new topic Reply to topic
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 01 Dec 2007, 22:16
Does anyone know where I can find some examples in asm = formulas?
a=-7
b=6
c=-2
d=-8
val = a+(b*c / d)
etc..
Stuff with +/- numbers ..
Floating point..
Using FPU regs?
I did find a little example of fpu in the Mandel.asm example on this forum are there any others?

Thanks in advance!


Last edited by dosin on 10 Dec 2007, 23:20; edited 2 times in total
Post 01 Dec 2007, 22:16
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 02 Dec 2007, 02:04
Erm... I'm assuming you're learning asm... First off... things are seldom done with signs, and that's just initializing space pre-assembling (ex "myvar dd -4-55*2"). If you want to change myvar to -7, you could do it this way.

"mov [myvar], DWORD -7 " (Note that DWORD means it's 4 bytes, assembly dosn't do type checking much, so it's always good to put DWORD in there just to be sure it's the right size.) Also note the "[]." In fasm, myvar is a pointer (the location in memory where the variable is) and adding [] means to use the value in it (or erase the value in it with the new value). This is almost always the furthest left "oprand."

as for "val = a+(b*c / d)"... You'll have to restructure... b will become "eax" instead because mul always gives answer in the eax register, same with div. Your equation becomes "val = a+(eax*c/d)" but even that can't be used directly unless a, b, c, and d are fasm's equivalent to HLL's "#define" or "const var." If it is a define, then it will work as is (put b back in place of eax), but if it isn't, it'll be as below...

Code:
;note: assumed that val and other stuff is already declared.
mov eax, [a]
mul [b]
div [d]
add eax, [a] ; or mov [a], eax depends on how you want, but if you're moving it to var, you'll want the first.
mov [var], eax ;keep the "von neuman bottlneck" (wiki it) in mind, and if you're using var right away, you don't have to move it to var but just use eax instead.    


As for FPU, that's more complicated, you'll want to get used to that first.
Post 02 Dec 2007, 02:04
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 02 Dec 2007, 02:50
Thanks for the post... I am trying to learm more on floating points and signed ints... for graphics..

div
idiv
mul
etc..

I do use these but for this purpose I need to learn more on the FPU...

I just put the (a*b,,etc.) for an example..using -/+ numbers/floating point..


I have set the screen up for 3D and then attempt to create a 3d graphics system lib..Thats why I need to learn more about FPU..
I am just looking for examples.. links..anything.. I have found some but don't go into much or give examples..and then later attempt 3DNow..
should have been more spec...sry!@ Cool
Post 02 Dec 2007, 02:50
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 02 Dec 2007, 12:18
Well if graphics, you're probably best with SSE for it can work with 4 at once and at this point i'm convinced that it's true that it's faster than the FPU, but that would take some work and searching. I'll do a different equation for FPU cause i'm in a hurry right now.

finit
fld [a]
fld [b]
faddp st1, st0
fstp [result]
;The stack is now clear
Post 02 Dec 2007, 12:18
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 02 Dec 2007, 16:24
I can't find the website, but there was a retired chemical engineer in the UK that had a ton of FPU stuff on his website. Don't even remember his name. If I can get to my other computer today I'll look it up in my archive.
Post 02 Dec 2007, 16:24
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 02 Dec 2007, 19:01
It looks like the FPU regs are on all the processors.. Thats why I am learning it first..I don't think SSE is on earlier processors..like the P,PII,K6,3D!

later I will add a chk for processor function to use the SSE if avail.
Quote:
you're probably best with SSE


If thats wrong let me know ....

is this that website...
http://www.ray.masmcode.com/

Thanks again for any help!!
Post 02 Dec 2007, 19:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 02 Dec 2007, 20:46
Nah, I was thinking of Ron Thomas, but his website does not respond:
http://www.rbthomas.freeserve.co.uk/

Thank goodness for the archive:
http://web.archive.org/web/*/http://www.rbthomas.freeserve.co.uk/
Post 02 Dec 2007, 20:46
View user's profile Send private message Visit poster's website Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 02 Dec 2007, 21:33
dosin,

Check out the excellent tutorial one by Raymond Filiatreault:

http://www.website.masmforum.com/tutorials/fptute/index.html

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 02 Dec 2007, 21:33
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 02 Dec 2007, 21:34
Thanks, I'll take a look!
Post 02 Dec 2007, 21:34
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 03 Dec 2007, 02:09
does -> finit need to before each one?
also I don't think this is right.. the code I posted! I am getting an idea of how to do it ..but still need some help.. This example covers the basic instructions with FPU add,sub,mul,div... Thanks for any help!

removed code not to confuse anyone learnig fpu!


Last edited by dosin on 10 Dec 2007, 23:07; edited 1 time in total
Post 03 Dec 2007, 02:09
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 03 Dec 2007, 04:25
Code:
               ; FPU stack:
fld [c]        ; c
fld [m]        ; m, c
fmul st0,st1   ; c*m, c
fld [z]        ; z, c*m, c
fsubp st2,st0  ; c*m, c-z
fdivrp st1,st0 ; c*m/(c-z)
fld [cr]       ; cr, c*m/(c-z)
faddp st1,st0  ; cr+c*m/(c-z)

fstp [val]    


FINIT puts the FPU in a known state - use it as often as you need to ensure that known state. If you manage the FPU stack well then this would be once at the start of your program, maybe. Here is the shorthand form:
Code:
fld [cr]
fld [m]
fld [z]
fld [c]
fmul st2,st0
fsubrp
fdivp
faddp
fstp [val]    
Notice the same number of load and "P"/pop instructions. Also, more stack space is required by the second version - four positions verses three for the first example.
Post 03 Dec 2007, 04:25
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 03 Dec 2007, 22:07
Thanks, for breaking it down!
That helped a lot!
Post 03 Dec 2007, 22:07
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 04 Dec 2007, 03:58
Packed addition and Subtraction

MMX padd(b,w,d,q) mmxdst,mmxsrc
SSE2 padd(b,w,d,q) mmxdst,mmxsrc

Has anyone used these functions here and have any comments on them?

I was looking in a book I have - but it just skips over it and does not give much info....

a= -125
b= 103
+____
result should be -22


mov eax,[a]
mov ebx,[b]
movq mm0,eax
movq mm1,ebx
paddb mm1,mm0
mm1 should equal -22

The above code is wrong and I am sure there is a better way..
If someone that has experience with this - and help can get me started?
Thanks in advance for anyhelp!!! Very Happy
I did find an article on it:
http://www.tommesani.com/SSE2MMX.html
Post 04 Dec 2007, 03:58
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 04 Dec 2007, 05:51
MOVD is used to transfer general purpose register to MMX. Not only are there different sizes - ways to partition 64/128 bit registers; but there are different way to use those partitions - (un)signed/(un)saturate.

It is good to read the instruction reference and then work through some small coding examples. Then challenge yourself with a small task: case conversion of text, vector math, etc.
Code:
movd mm0,eax
movd mm1,edx
addsb mm0,mm1
movd eax,mm0    
This example isn't parallel. Also, the use of MOVD is the sign of a bad implementation, imho. I try not to use it.
Post 04 Dec 2007, 05:51
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 04 Dec 2007, 12:58
FPU tutorial:
http://www.ray.masmcode.com/tutorial/index.html

The way I learned FPU programming was to look at the output of a compiler (together with the fasm instruction reference). Since my own compiler generates much less optimized and strangled output than gcc, I recommend it. Download it from here: http://home.no.net/tsg1zzn/c21.zip

Type the program into notepad, and type c -a program.rq to generate an asm file.

Here's an example program:

Code:
new a as real
new b as real
new c as real
new d as real
new val as real

a=-7
b=6
c=-2
d=-8
val = a+(b*c / d)    
Post 04 Dec 2007, 12:58
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 04 Dec 2007, 22:16
Thanks .. Thats a great app...
I used this for the code : c = a / b
for a test!
c -a test.c
and got this output file..

Code:
; Code generated by Rapid Bull
 format MS COFF
      public TEST^MAIN
    TEST^MAIN:
      push   rq_ZeroDataEnd-rq_ZeroData
   push   rq_ZeroData
  call   rq_ZeroMemory
        fld    qword [rq_f0]
        fstp   qword [rq_global+0]
  fld    qword [rq_f1]
        fstp   qword [rq_global+8]
  fld    qword [rq_global+0]
  fdiv   qword [rq_global+8]
  fstp   qword [rq_global+16]
 ret    
     extrn  rq_AllocateArray
     extrn  rq_StrFree
   extrn  rq_StrCopy
   extrn  rq_StrConcat
 extrn  rq_StrConcatFreeA
    extrn  rq_StrConcatFreeB
    extrn  rq_StrComp
   extrn  rq_ZeroMemory
        extrn  rq_DebugS
    extrn  rq_DebugL
    ; Variables:
    section '.bss' data readable writeable
    rq_ZeroData:
    rq_global:
      v_A rb 8
    v_B rb 8
    v_C rb 8
    rq_ZeroDataEnd:
 ; String and float literals:
    section '.data' data readable writeable
   rq_f0 dq 4636737291354636288
        rq_f1 dq 4632233691727265792
    




Would you mind braking this down to fasm..for an example...
Code:
       
        fld    qword [rq_f0] 
      fstp   qword [rq_global+0] ?
        fld    qword [rq_f1]
        fstp   qword [rq_global+8] ?
        fld    qword [rq_global+0]
  fdiv   qword [rq_global+8] 
 fstp   qword [rq_global+16]?

                v_A rb 8
        v_B rb 8
    v_C rb 8
    


TY!
Post 04 Dec 2007, 22:16
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 05 Dec 2007, 16:00
rq_global+X is an offset from rq_global, which is defined later in the file. Here v_A is +0, v_B is +8 and v_C is +16.

Code:
        fld    qword [rq_f0]  
        fstp   qword [rq_global+0]    

Load the float stored at rq_f0 (that's a constant in your source).
Store the float you just loaded at rq_global+0 (that's v_A).

Code:
        fld    qword [rq_f1] 
        fstp   qword [rq_global+8]    

It's same, but with a different constant and with a different v_B.

Code:
        fld    qword [rq_global+0] 
        fdiv   qword [rq_global+8]  
        fstp   qword [rq_global+16]    

Load v_A (+0)
Divide by v_B (+Cool
Store in v_C (+16)

If you start a line with a ! and then some text you will get that placed directly into the asm file, so you can see what asm code corresponds to which statements. Example:
Code:
! ; a = 6:
a = 6
! ; b = 3:
b = 3
! ; c = a/b
c = a/b    

Generated asm:
Code:
 ; a = 6:
        fld    qword [rq_f0] 
        fstp   qword [rq_global+0] 
 ; b = 3
        fld    qword [rq_f1] 
        fstp   qword [rq_global+8] 
 ; c = a/b
        fld    qword [rq_global+0] 
        fdiv   qword [rq_global+8] 
        fstp   qword [rq_global+16]    
Post 05 Dec 2007, 16:00
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 09 Dec 2007, 23:20
I need some help... Everything works fine with positive numbers.. when I enter a - numb... it calculates wrong? Can someone help me figure this out? I have tride chaging fsub to fisub etc..


dist dd 0
camera dd 256
xcenter dd 399
ycenter dd 299
VesaZ dd 128
VesaY dd -3
VesaX dd -10

also many thanks to- Plue for the help!
Thanks in advance for anyhelp!


Last edited by dosin on 10 Dec 2007, 23:06; edited 1 time in total
Post 09 Dec 2007, 23:20
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Dec 2007, 23:33
Perhaps you have another problem also but this:
Code:
dist dd 0
camera dd 256
xcenter dd 399
ycenter dd 299
VesaZ dd 128
VesaY dd -3
VesaX dd -10    
Is wrong, you are defining integers rather than floats so either use "fixxx" for every FPU instruction that accesses integer data on memory or change the data definition to this:
Code:
dist dd 0f
camera dd 256f
xcenter dd 399f
ycenter dd 299f
VesaZ dd 128f
VesaY dd -3f
VesaX dd -10f    
Post 09 Dec 2007, 23:33
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 10 Dec 2007, 00:05
okay.. Problem solved!
This was causing it to fail!
Quote:

dist dd 0f
camera dd 256f
xcenter dd 399f
ycenter dd 299f
VesaZ dd 128f
VesaY dd -3f
VesaX dd -10f

changed to:
Code:
dist      dd 0
camera          dd 256
xcenter       dd 399
ycenter       dd 299
GVesaZ        dd 0

GVesaX      dd 0
GVesaY          dd 0
    


and to use:
Code:

mov [VesaX], -10.0f
etc..
call Draw3D_Pix
    

Draw3D_Pix uses fpu to calc the the x,y,z coords..

now to start on a line function for drawing a cube..

any sugestions on a function for a plane or quad?
Post 10 Dec 2007, 00:05
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.