# Preferred calculation methods of an assembler

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

## 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 on other sites
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 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 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 on other sites
Multiplication and Division occur first before addition and subtraction. Don't break those rules.

##### 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 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.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633718
• Total Posts
3013518
×