Hi, a few days ago I was reading a post on tutorials and I noticed a couple of people asking about FPU tutorials. I offered to help people with any specific problems they may have and it got me thinking. I would be happy to write some tutorials on this topic. Theres no point doing simple bginners tutorials as the MASM reference and AoA 16bit are both quite good for that, but there are certain techniques to programming large equations in the FPU. Unfortunatly off hand I can't think of any good topics so I'm open to suggestions. Specific problems would probably make for better tutorials as they could come in two parts. 1) A very mathamatically orianted section covering the creation of formula for the problem and optimising the formaul specifically for the FPU. 2) How to program the formula efficintly and any additional thecniques related to the FPU. Just a suggestion.
Posted on 2001-03-31 16:34:00 by Zadkiel
Well I would like to see an MP3 encoder/decoder written 100% in assembler. The formula's are available at www.wotsit.org - Look for the description of the MP3 file format their is some C source code for a MP3 encoder/decoder. The equations are definately not simple! The only thing is you all have to remember that you may not use MP3 technology for commercial purposes without a licence from the guys who own the rights (the licensing info can be dug up if necessary on the net). That's my suggestion! Thanks, Ben
Posted on 2001-03-31 16:45:00 by cyberben
How about a simple 3D renderer? Just some geometric primitives, a light, and a camera. bitRAKE
Posted on 2001-03-31 16:50:00 by bitRAKE
Zadkiel, One of the things in very short supply for assembler programmers is some basic data on how to use the FP registers, how to load them, perform calculations, store intermediate results, place them results back in integer registers etc .... If you have the time to do an overview on setting up and using floating point registers, many people would appreciate the effort. Regards, hutch@pbq.com.au
Posted on 2001-03-31 16:52:00 by hutch--
I think a tutorial series on a simple 3D renderer would be a good suggestion. If kept in a simple wireframe mode initially then it shouldn't take more than 3 tutorials and the first one could be a basic description on the FPU. I'll see what I can do.
Posted on 2001-03-31 17:01:00 by Zadkiel
Aren't you lucky. I decide to write the first tutorial tonight. Its an rtf at the moment, download it and the code here. If this isn't clear enough in places then just ask me. Good Luck
Posted on 2001-03-31 20:07:00 by Zadkiel
Zadkiel, This is one of the best tutorials I have ever read! Why? It is simple to read and has graphical explanation. In the past I have learnt mainly by reading already compiled code Many times I have come across this FLD and so on. I ignored these instructions as they didn't have any meaning to me. Actually I have never had a need to use them. But after reading your first tutorial I feel that I understand everything. I mean if you don't write software for a Space Shuttle you don't need to know much more. After this it is more a knowledge of Math. than anything else. Recently I got hold of "OllyDbg version 1.02" where one could even see the content of these (st) registers. Your tutorial in conjunction with this debugger makes things very clear. Thanks for thef knowledge you have given me. forge
Posted on 2001-04-04 03:45:00 by forge
Bravo! I don't have words for complements. The more you'll write the better. PS. Put uses ebx edi esi on your callback DlgProc. Otherwise it crashes in NT. Reason, IMHO, some proc your DlgProc calls uses some of the registers. I checked. Put preservation code and it stoped genarate GPF. The Svin.
Posted on 2001-04-04 06:23:00 by The Svin
I can't believe!!! I past all yesterday tonight studing FPU. I was thinking in, later my study, write some tutorials about float point because I had difficulties for find some text about it and I know people needing that tutorials. Now we have Zadkiel's tutorials. I didn't read it yet but, for the reaction of others coders I know that it's good. (I'll read it later). Anyway, if Zadkiel need some help, I'll be wonder if I'll can help. The 3D rendering is a very cool theme! cu guys. :)
Posted on 2001-04-04 07:09:00 by wolfao
Thanks for the feedback, its extreemly encouraging. The 2nd tutorial is almost finished. The base code is working actually and the tutorial is almost finished. I expect by Sunday at the latest it will be done. I just don't have much free time during weekdays. There a modification to the code that I want to mention. I was using the following metho to square the value in st(0) fld st fmul actaully fmul st, st is faster. Note that both methods do work. upload the corrected source so anyone else who downlaods it will be fine. P.S sorry about any spelling mistakes, its not the I don't speak English nativly its just that I'm very bad at typing (and spelling in general), plus I was using wordpad and there no intregated spellchecker. I'll get those sorted out once the three tutorial are finished. This message was edited by Zadkiel, on 4/4/2001 5:41:28 PM
Posted on 2001-04-04 14:41:00 by Zadkiel
Zadkiel: That was a great tutorial that you made for the FPU. I really enjoyed it and learned a lot. I really hope to see some more tutorials soon. Thanks again, Bob.:)
Posted on 2001-04-04 19:46:00 by BobMcK
Hey Zadkiel, This is so funny, I just entered this message board in order to ask for a floating point tutorial and I see that you wrote one I just read it, and it's great man! Keep up the good work :) hmm about the Distance Formula in C/C++ it should be like this: Dis = SQRT( ( (X1 - X2) * (X1 - X2))+( (Y1 - Y2) * (Y1 - Y2) ) ) instead of: Dis = SQR( ( (X1 - X2)^2)+( (Y1 - Y2)^2 ) ) because ^ means XOR so you did *(X1-X2)XOR2 :) that's it thanks http://qsoft.cjb.net
Posted on 2001-04-06 02:51:00 by Arkon
Zadkiel, I've had a look at your tut1 and found a typo: fld R4Val2 St(0) = St(0) + R4Val2 St(1) = 0 St(2) = 0 St(3) = 0 St(4) = 0 St(5) = 0 St(6) = 0 St(7) = 0 You typed fld R4Val2 instead of fadd R4Val2. As for the rest. Well written, man. Write more. I'll send you some thoughts later via email. The Svin.
Posted on 2001-04-19 06:50:00 by The Svin
Thanks Svin, I'l correct that and upload it again. And actually Arkon, thank you as well sorry I didn't reply earlier, I think I had disconnected by the time I saw your post and then I forgot. Anyway enough excuses, your right of course, the code I said was C code was actually VB. Thanks.
Posted on 2001-04-19 16:17:00 by Zadkiel
About your dialog. I think, for working with real numbers you need 1. Limit number of simbols the edit controls accept. 2. Filter out incorrect simbols It's simple with integers 'cause there is ES_NUMBER style for edit, wich exept nothing but numbers in edit control. But with floats we need dot. So I recommed some start code. There is Hutch's subclass proc that perfectly suites this purpose, I've changed it a little to make shorter and faster and also add some code to limmit text input in short manner. You can use it if you like in tutors when you use this dialog (I also think it's better to add lables before edit control to make the dialog more demonstrative(? don't know if it's good Eng. but hope you understand what I mean)


.586
.model flat,stdcall
option casemap:none

include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\masm32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
EdRealNum PROTO :DWORD,:DWORD,:DWORD,:DWORD
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

FltOut MACRO FltVal, EditH
	invoke FloatToStr,FltVal,addr buffer
	invoke SetDlgItemText,hWnd,EditH,ADDR buffer
EndM

FltIn MACRO pFltVal,EditH
	invoke GetDlgItemText,hWnd,EditH,ADDR buffer,512
	invoke StrToFloat,addr buffer,pFltVal
EndM

.data 
DlgName db "FPUBasics",0
AppName db "FPUBasics",0
Onef real8 1.0f

.data?
R8t Real8 ?
hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 512 dup (?)

.const
IDC_BUTTON equ 3001
IDC_EXIT equ 3002

IDM_ADD 	equ 32000
IDM_DISTANCE 	equ 32001

IDM_EXIT	equ 32003

.code

start:
	invoke GetModuleHandle,NULL
	mov hInstance,eax
	invoke DialogBoxParam, hInstance,ADDR DlgName,NULL,addr DlgProc,NULL
	invoke ExitProcess,eax

DlgProc proc uses edi esi ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.data?
ALIGN 4
EditProc dd ?
.code
	.IF uMsg==WM_INITDIALOG
		invoke GetDlgItem,hWnd,3002
		mov edi,eax 		;handle of one of the edit controls
	;	invoke SetFocus,eax	;you don't need this
		invoke SetWindowLong,edi,GWL_WNDPROC,offset EdRealNum ;subclass first edit
		mov EditProc,eax
		invoke CallWindowProc,eax,edi,EM_LIMITTEXT,24,0 ;set limit to 24 digits
		mov esi,3003
		mov ebx,hWnd
;subclass and set limits to the rest of controls
	@@:	invoke GetDlgItem,ebx,esi	;ebx=hDialog esi = ID of edit control 
		push eax			;save handle for EM_LIMITTEXT
		invoke SetWindowLong,eax,GWL_WNDPROC,offset EdRealNum ;subclass
		pop edx			;handle of control
		invoke CallWindowProc,eax,edx,EM_LIMITTEXT,24,0 ;eax = editproc
		inc esi		;next control
		cmp esi,3007	;check if we are done with all edits
		jne @B		;IF NOT proceed with next control

	.ELSEIF uMsg==WM_CLOSE
		invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0
	.ELSEIF uMsg==WM_COMMAND
		mov eax,wParam
		.IF lParam == 0
			.IF ax==IDM_ADD
				;This adds the contents of the first two edit boxes
				;and returns the result in the last box
			finit	;Initialize the FPU
			FltIn offset R8t,3002
			fld R8t	;load R8t to st(0)
			FltIn offset R8t,3003
			fadd R8t	;add R8t to st(0)
			fstp R8t	;Pop st(0) into R8t
			
			FltOut R8t,3006

			.ELSEIF ax==IDM_DISTANCE
;This is an example of slightly more complicated
;calculation - the distance between two points
;Edit1 is taken as X1
;Edit2 is taken as Y1
;Edit3 is taken as X2
;Edit4 is taken as Y2
;I believe the C code for this is
;Dis = SQR(((X1-X2)^2) - ((Y1-Y2)^2))
			finit		;initialise the FPU
			FltIn addr R8t, 3002
			fld R8t		;st (0)
			FltIn addr R8t, 3004
			fsub R8t		;st(0)=st(0)-X2
			fld st		;st(1)= st(0),st(0)=st(0)
			fmul		;st(0)= st(0)*st(1)

			FltIn addr R8t,3003 ;st(0)=Y1
			fld R8t
			FltIn addr R8t,3005
			fsub R8t		;st(0)=st(0)-Y2
			fld st		;st(1)=st(0)
			fmul		;st(0)=st(0)*st(1)

			fadd		;st(0)=st(0)+st(1)
			fsqrt		;st(0) = SQR( st(0))

			fstp R8t		;Pop st(0) into R8t
			FltOut R8t,3006

		.ELSEIF ax==IDM_EXIT
			invoke EndDialog, hWnd,NULL
		.ENDIF
	.ENDIF
.ELSE
	mov eax
Posted on 2001-04-19 17:56:00 by The Svin
Well, a truly excellent suggestion. Admitingly I havn't tested it yet but I trust it works, when I get a proper chance later I'll implement it and upload the code. But I have a question, would this confuse beginners? With comments it shouldn't, but I keep thinking back to what I hate most about source code when your beginning to learn a new topic, I dislike all the bells and whistles that in my opinion make things look more complicated than they are. Its awful when your a beginner (this applies to anything of course, not just ASM) and your trying to pick out the bare essentials of code necessary to work out of a large source code. I don't think this addition would have that effect, this is just a more general concern really. While I'm here I have an important question about the 4th tutorial, should I bother really? Now I'm serious here, I wrote the third one on 3D maths as that was one of the early suggestions I got the forth one was supposed to be on optimising the maths of that code, as I said alot of calculation take place that lead to a 1.0 or a 0.0 and this but really be optimised. Unfortunatly the optimisations are all maths based, its all the type of stuff that you sit down with a pencil and paper and just work out, very few actual programming techniques are used. Also I'm awful at explaining maths to people through any method other than talking to them. I suppose I just feel that the third tutorial was very specific and probably wouldn't be of alot of help to most, if I do write the forth it would be even more specific and have an even narrower range of people that would want it. I liked the first two tutorials as I felt they covered the problem I ran into when I first started FPU maths, I'm stuck now as to weither theres any need for a 4th tutorial at all. I'm open to suggestions. Perhaps the best way I can describe what type of tutorial I like to write is to give an example: I was doing alot of OpenGL work about a month ago and I wrote a program that displayed VistaPro landscapes for a game I intended to write. I ran into a problem though where by I needed to be able to judge the height at any point, not just at the vertices which I already knew. A couple of question on the OpenGL forums proved fruitless so I sat down worked out a formula and wrote my own routine for calculating the height at points not just on vertices but across the face. You can find a badly written tutorial explaining this on my site. Its this type of problem that I feel makes the best tutorials (when their written properly of course). I'd love to build up a collection of such tutorials, but I don't have any problems to write them on. Well actually I do, but its an extraordinarly complicated statics simulation that will take a couple of weeks at least. This is where I need input, thats of course if ye have any problems, maybe you don't. As I said this is just I opinion on what I feel tutorials should be about, not whole projects, just particular problems Hmm.. theres my two cents anyway. I've just onw more question to ask but its not entirly related to FPU tutorials so if your tired of reading theres no need to continue This is just a question on the revelance of tutorials related to 3D maths, the GeForce can profrom all those translations in hardware, surely trying to optimsie them in assembly is silly when theres a seperate chip sitting there dieing to be used, assuming you have a GeForce that is. If you don't then maybe optimising the maths is a good idea but any work on the drawing aspect should be left to 3D cards as they're just so fast at it.
Posted on 2001-04-20 13:46:00 by Zadkiel
1. About code for edit controls. You are generally right about risk that complex code trapps beginners while they stady simple particular subject and those additions on demo's sources stay on their way to understand this subject. This your opinion makes me even more sure that you're right man as tutorialist. As to this particular subclass edit proc - you can mark it out with some comments like: ; This code makes sure that edit control will accept nothing ; but digits and no more than one dot and limit it to 24 simbols altogether. So student can abstruct this code from essential one relative to FPU studing. 2. About tutorials. General suggestion - follow your heart. Write what you would have loved to read when you were a beginner. IMNSHO the basics needs to be extended. The more tutors the better. Step by step. Even if you'd write a collection of tutors simply based on big set of common pracicaly popular math formulas and their realisation on fpu - I bet it would become a bestseller on the net. There is nothing of the kind yet. Like there is no monumental work about main algorithms realisation on asm. The only book - D.Knuth AOP but it's better be witten for real CPU not MIX :) People need both - revision (or even studing from scrach) their math knowlidge and tecniques of realisation of it on FPU. People need even more - text book: Math theory + Fpu theory + good and short practical examples + exersizes for selfwork on subject. Do as much as you can from it. LOOK around! Assembler programming topics and even simple math topics and most rare things! You can find a lot of unefficient code from both math and programming point of view in 99% cases you'll see a\b\c instead of a\(b*c) not mentioning more complex formulas. We need learn APIs INTs ports macros ect. and this is what peaple is doing most of the time but we also need to learn opcodes programming from easy rutines to complex algos. And I can not see it much. We lack it. I love words that Hutch said first time when you had asked if people would need tutors on FPU. Beginners need step by step very easy to easy progressive tutors. 4? Hundreds! Step by step! Why you so affraid that you narrowed your audience? May be there are another future A.Fog among them? Doesn't she worth more than the rest :) Jocking. I think you're right about "not whole projects, just particular problems". But at the some logical end of part of such problems lessons you may write project wich will include all discussed problems. You must keep in mind simple thing (I actually think you know it better then me) - the value of tutorial mesured not by info included in it but info understood from it by the reader. That's why people so love Iczelion tutors. There are lots of more monumental works both on assembly itself and Windows. But it's rare to find such a clearity and simplicity that is in Iczelion tuts (it said by the man who had complitly differen style than Icz but admire style in wich the tutors are written). Your tutors have the clarity and simplicity - so it doesn't matter what topic would you choose next as long as it'll be written in the style. As to subject I prefer - I said - school math textbook in FPU. From leanear equation to trigonomethry. The Svin.
Posted on 2001-04-20 15:47:00 by The Svin
The Svin I've just implemented your code, I had to make one minor alteration I changed mov ecx, sizeof Buffer ;byte count in ecx to mov ecx, eax ;byte count in ecx As this is done after the API call eax contains the number of characters to search so this is more efficient. Also more importantly when I tested it there must have been something in the Buffer string after the text entered that messd up the search and the "jne accept" never jumped Your right about the tutorials and indeed your statement "As to subject I prefer - I said - school math textbook in FPU. From leanear equation to trigonomethry." Is one I wholeheartitly agree with. Indeed that is my favourtie aspect of maths and probably the most useful for games also. So if anyone has any maths problems or equations post them or e-mail me and I'll see if I can write a tutorial. In the mean time I'll see if I can find any ones of interest.
Posted on 2001-04-20 19:40:00 by Zadkiel
You change to move ecx,eax makes it better. As to jne accept effect - I did it on perpose - so that dot can not be the first simbol. Though .1234 is acceptable in some notations I personaly prefer it to be 0.1234. To Hutch: Your Edit class (changed by Zadkiel and me) will become popular though his tutorials :) The Svin. This message was edited by The Svin, on 4/21/2001 6:39:03 AM
Posted on 2001-04-21 06:38:00 by The Svin