Search code examples
assemblycomputer-sciencecpu-architecture

How to write the 3- address mode instruction if we have question like this z=y*u*(a+e)+w*a+e


if I'm following the BODMAS rule then

add x,a,e
mul v,x,u
mul g,v,y
mul o,w,a
add q,o,g
add z,q,e

Is this right? if not then what should I do


Solution

  • To be honest, it is the first time I hear from this rule, but I still want to share my thoughts :)

    Brackets first

    Orders n/a

    Division and Multiplication (left to right)

    Addition and Subtraction (left to right)

    I think your only "problem" here is that you don't respect the left to right rule. In general this should apply to everything.

    So it should be:

    x=a+b  |   add x a b
    z=y*u  |   mul z y u
    v=z*x  |   mul v z x
    o=w*a  |   mul o w a
    q=v+o  |   add q v o
    z=q+b  |   add z q b