Message board for the users of flat assembler.
> Main > 3D Problem Solved
dosin 01 Dec 2007, 22:16
Does anyone know where I can find some examples in asm = formulas?
val = a+(b*c / d)
Stuff with +/- numbers ..
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
|01 Dec 2007, 22:16||
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...
;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.
|02 Dec 2007, 02:04||
dosin 02 Dec 2007, 02:50
Thanks for the post... I am trying to learm more on floating points and signed ints... for graphics..
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!@
|02 Dec 2007, 02:50||
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.
faddp st1, st0
;The stack is now clear
|02 Dec 2007, 12:18||
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.
|02 Dec 2007, 16:24||
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.
you're probably best with SSE
If thats wrong let me know ....
is this that website...
Thanks again for any help!!
|02 Dec 2007, 19:01||
bitRAKE 02 Dec 2007, 20:46
|02 Dec 2007, 20:46||
farrier 02 Dec 2007, 21:33
Check out the excellent tutorial one by Raymond Filiatreault:
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!
|02 Dec 2007, 21:33||
dosin 02 Dec 2007, 21:34
Thanks, I'll take a look!
|02 Dec 2007, 21:34||
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
|03 Dec 2007, 02:09||
bitRAKE 03 Dec 2007, 04:25
; 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:
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.
fld [cr] fld [m] fld [z] fld [c] fmul st2,st0 fsubrp fdivp faddp fstp [val]
|03 Dec 2007, 04:25||
dosin 03 Dec 2007, 22:07
Thanks, for breaking it down!
That helped a lot!
|03 Dec 2007, 22:07||
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....
result should be -22
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!!!
I did find an article on it:
|04 Dec 2007, 03:58||
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.
This example isn't parallel. Also, the use of MOVD is the sign of a bad implementation, imho. I try not to use it.
movd mm0,eax movd mm1,edx addsb mm0,mm1 movd eax,mm0
|04 Dec 2007, 05:51||
Plue 04 Dec 2007, 12:58
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:
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)
|04 Dec 2007, 12:58||
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 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...
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
|04 Dec 2007, 22:16||
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.
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).
fld qword [rq_f1] fstp qword [rq_global+8]
It's same, but with a different constant and with a different v_B.
fld qword [rq_global+0] fdiv qword [rq_global+8] fstp qword [rq_global+16]
Load v_A (+0)
Divide by v_B (+
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:
! ; a = 6: a = 6 ! ; b = 3: b = 3 ! ; c = a/b c = a/b
; 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]
|05 Dec 2007, 16:00||
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
|09 Dec 2007, 23:20||
LocoDelAssembly 09 Dec 2007, 23:33
Perhaps you have another problem also but this:
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:
dist dd 0 camera dd 256 xcenter dd 399 ycenter dd 299 VesaZ dd 128 VesaY dd -3 VesaX dd -10
dist dd 0f camera dd 256f xcenter dd 399f ycenter dd 299f VesaZ dd 128f VesaY dd -3f VesaX dd -10f
|09 Dec 2007, 23:33||
dosin 10 Dec 2007, 00:05
okay.. Problem solved!
This was causing it to fail!
dist dd 0 camera dd 256 xcenter dd 399 ycenter dd 299 GVesaZ dd 0 GVesaX dd 0 GVesaY dd 0
and to use:
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?
|10 Dec 2007, 00:05||
< Last Thread | Next Thread >
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.