Many thanks Sayeh,
Yes - I use 50 lines of asm because it is quicker not because I have nothing else to do!
I take your comments re the cache but I am just going on timings and what I have done is the fastest so far - if somebody can make a faster "switch()" that would be great .... any offers?
Concerning the layout I lost a lot of clarity by not using the code tag on my post here - I religiously indent to avoid lost brackets! The reason I put the labels on the same line is that this stuff runs to well over a thousand lines as it is ...
"Glad you are enjoying assembler. It will serve you well. If you learn what's going on in assembler, you will run rings around most
OOPs programmers without much effort when you code in C or C and assembler. "
Yes. I had rather assumed that which is why I am writing in C and asm. There has to be an overhead with OOP. Ultimatelly all code reduces to series of if tests ( cmp actually ) and goto statements - rather like badly written BASIC.
Actually, there is a certain irony here because the program I have written is a Genetic Programming environment ie you start with a set of random computer instructions and the whole lot evolves into a program over millions ( billions ) of generations via mutation and breeding. If you are interested I could write more but as an example here is a program which evolved to find cube roots (I am not totally sure how it works but it does to 16 places of decimals - and is more accurate than math.h .... the 8 lines with labels are what evolved - the other stuff is padding. I love the symmetry of lines 6 and 8 .... ) If you try it with other numbers it may work or it may just loop .... evolution is not perfect!
Code:
//"x" is the number for which we require the cube root
//the answer appears in "a" The format here is BASIC
1: c = x + 3
2: a = c / 3
3: c = a * a
4: c = x / c
5: c = a + c
6: if c > 3 * a goto 2
7: c = a + c
8: if c < 3 * a goto 2
A working version in C follows:
// found on 6th Jan 2002 by newbld.c
//"x" is the number for which we require the cube root
//the answer appears in "a"
#include<math.h>
#include<stdio.h>
main(){
double a,b,c,d,sys;
double x = 99.9;
long j=0;
system("cls"); //clear screen
lab1: c = x + 3;
lab2: a = c / 3;
j++;
printf("%lu solution so far - root is %16.16f \n",j, a);
lab3: c = a * a;
lab4: c = x / c;
lab5: c = a + c;
lab6: if ( c > 3 * a) goto lab2;
lab7: c = a + c;
lab8: if (c < 3 * a) goto lab2;
printf("Cube root of %5.3f is %16.16f and that cubed is %16.16f \n", x, a, a*a*a);
sys= pow(x,(double)(1)/3);
printf("Math root of %5.3f is %16.16f and that cubed is %16.16f \n", x,sys,sys*sys*sys );
}
I guess this is not really the right forum for this but what the heck ...