Jump to content
  • Advertisement
Sign in to follow this  
PRS102076

Preferred calculation methods of an assembler

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there I am putting together an assembler for my OS. At present, the routines which build numbers and perform arithmetic on behalf of the programmer assign a level of precedence to each operator. So for instance 5 + 5 * 5 is processed as 5*5 first, and then the addition takes place because multiplication has a higher priority. This is standard operation in all assemblers I have come across. Its just that is occured to me that sometimes I myself would prefer a totally linear method of arithmetic, so that an addition would be processed before a multiplication if that were the order in which they were encountered. So just out of curiosity, does anyone else prefer this method under any circumstances, with the option to parenthesize any terms to ensure a specific order of operator usage? If not I will file it under 'pointless ideas'... thanks in advance Patrick

Share this post


Link to post
Share on other sites
Advertisement
generally i think operator precedence is assumed to be what it is in C. i.e. my TI-80 calculator has the same operator precedence, as does MS excel, as does python, C, C++, VB, etc, etc, etc. I think it would be very very confusing to have non-normal operator ordering. Parenthesis are standardly used if you want out of order execution.

-me

Share this post


Link to post
Share on other sites
I think that will be a bad design choice, with all respect :) . I mean: parenthesizing is just the regular way of doing math, and if you change the rules of precedence, it will only confuse most of the people. There are rules on how to calculate something and if you write down common things like this. you will get weird results.

c = sqrt(a*a + b*b);

We learn how to use parentheses from the sixth grade or something, i can't even rememeber. And only people who don't know how to do basic math will benefit from this feature. I am sorry if this sounds a bit blunt :)

Good luck and greetings.

Share this post


Link to post
Share on other sites
Hi guys,
I have already implemented the standard, *proper* version of arithmetic, but you're right, any extra, nonstandard methods would just cause confusion. I got what I wanted, which was a second opinion, so thanks again
Patrick

Share this post


Link to post
Share on other sites
A halfway house is also an option: prioritize multiplication and division before addition and subtraction, but when it comes to prioritization between multiplication and division, or between addition and subtraction, base it on the order in which the signs appear. For example:

a*b/c = (a*b)/c but a/b*c = (a/b)*c and NOT a/(b*c)

However, a+b/c would give a+(b/c) as normal.

Just a suggestion.

Share this post


Link to post
Share on other sites
If you want to make it totally 'linear' than the assignment also has the follow the expression.. for example:

a + b * c = x

This idea can be taken quite far.. a literal expression evaluator for a literal language.. "load a, add b, multiply by c, store in x"

But within the confines of a language whos express purpose isnt to be so literal, then it'll probably be a completely unvalued complication.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!