Reverse engineer the following Marie code, i.e. translate it into high level language such as C++.
/ Example 4.2
ORG 100
If, Load X
/Load the first value
Subt Y
/Subtract the value of Y, store result in
AC
Skipcond 400 /If AC=0, skip
the next instruction
Jump Else
/Jump to Else part if AC is not equal to
0
Then, Load X
/Reload X so it can be doubled
Add X
/Double X
Store X
/Store the new value
Jump Endif
/Skip over the false, or else, part to end of if
Else, Load Y
/Start the else part by loading Y
Subt X
/Subtract X from Y
Store Y
/Store Y-X in Y
Endif, Halt
/Terminate program (it doesn't do much!)
X, Dec 12
/Load the loop control variable
Y, Dec 20
/Subtract one from the loop control variable
END
ORG 100 // This mean our program will start the instruction from 100 address
Instruction 1 to 4 will make our if
condition:
1. Load X // This statement will load content of
X in the AC
2. Subt Y // This statement subtract the content
of address Y from the AC
3. Skipcond 400 // This will skip the next instruction if
AC=0
4. Jump Else // Unconditional branch to Else by
loading else in the program counter
Condition: if(x==y) as 400 code in Skipcond will tell us if content of AC=0 then skip the next instruction otherwise it will execute next instruction and in next instruction we are moving to the else part.
Instruction 5 to 7 will make body of our if
condition:
5. Then, Load X //This
statement will load content of X in the AC
6. Add X //Add content of X to
the AC
7. Store X //Store the content
of AC at X
8. Jump Endif //Unconditional
branch to Endif by loading Endif in the program counter.
Body: x = x + x; This statement will be the part of if condition which is already written from instruction 1 to 4.
Instruction 9 to 12 will make body of else in the if -
else condition:
9. Else, Load
Y //This statement tells that execution of else
part of condition is started, it will load content of Y in the
AC
10. Subt X //This statement subtract the content
of address Y from the AC
11. Store Y //Store the
content of AC at X
12. Endif, Halt //This tell that this is the end
of our code that is our if condition.
Body: y=y-x;
This last part is nothing but directions to assembler to
initialize the memory associated with X to DECimal12 and Y to
DECimal 20.
13. X, Dec 12
//Load the loop control variable
14. Y, Dec 20
/Subtract one from the loop control variable
15. END
Reverse engineered code in C++ for above marie code is:
if(x==y) {
x = x + x;
} else {
y = y - x;
}
Reverse engineer the following Marie code, i.e. translate it into high level language such as C++....