MAC-1 assembly recursion sample - recursion

I have the similar question as described here: MAC-1 assembly recursion
But I am a total newbie for MIC-1 / MAC-1 and looking for some ideas / samples on how to start. I need to calculate a faculty via recursion in MAC-1 ...
Thanks!

Well to get used to the MIC-1 simulator, use the following link:
http://www.ontko.com/mic1/mal.html
But before that, I guess you want to understand how the MIC-1 microprocessor works. Use chapter 4 of this textbook to understand all that is involved:
Structured Computer Organization 6th edition by Andrew S. Tanenbaum

Related

Does anyone remember “!” (Explanation point) being referred to as “bang” or “baseball bat”

I’m a former programmer who programmed in Unix and C in the early eighties. We used to refer to the “!” (Explanation point) as “bang” or “baseball bat”. I could not find that in any dictionary on the web. I worked at bell labs in Homdel NJ. Anyone ever heard of this? Just a little nostalgia

How to count bits using Marie assembly language?

I'm currently working a project where I use MARIE Assembly Language to create a version of Hamming code. My initial work has been to first have the user input the 8 bits for the data bits, and to then have the program output the correct 12-bit code word.
In order to find the correct values for the parity bits, I thought that the easiest way might be to load each data bit, which corresponds to a certain parity bit, and to count the number of 1s. However, I have yet to have found a way to have Marie count bits. I know there is no direct instruction to make Marie count bits, but does anyone have any advice on which instruction(s) might lead me towards an answer? I apologize in advance if clarity is lacking, and if it is please let me know so I can edit my question accordingly.

what happens to Schweizer T-Norm when p goes to zero?

I am reading Jang's book of Neuro-Fuzzy and Soft Computing and in the 2nd chapter the author talks about Schweizer and Sklar T-Norm which is presented by this equation:
it's a handy T-norm. in the exercises (#20 page 45) it asks what would happen to the Tss(a,b,p) if p->0
In fact it asks to show that the whole equation is going to be just ab in the end.
I tried different things and at last, I used Ln but I got this: -1/p Ln(a^-p + b^-p) and I have no idea where to go from here!
can anybody suggest anything? thanks for your help.
p.s: is there any simple way of expanding Ln(x+y) generally?

Annotated Ada language (Anna)

I am a beginner on Ada language and I would like to know what notations means. I have read in Kreuger software reuse paper that Anna is a an annotation language to describe Ada. Is that consider to be a formal comment for Ada code ?
For example:
subtype EVEN is INTEGER;
--| where X : EVEN = ) X mod 2 = 0;
The 2nd line is Anna annotation for the first line which is Ada code.
Is the 2nd line just a comment to let the user understand the first line or is it a constraint that is a "must" to mention not just an optional line?
I am really confused
Anna is ancient, do not waste your time with it.
There are a number of places to get starting with Ada. Among them is the Ada Wikibook, and the Ada Information Clearinghouse (AdaIC) maintains a list of suggested resources.
If you're interested in formal logic as it applies to Ada, you'll want to look into SPARK ("SPARK is a programming language, a set of source code analysis (static verification) tools, and a design method for developing high-assurance software.") Here's a quick overview and tutorial, though you may not want to tackle that until you've got some practice with Ada under your belt.
You probably already know about the GNAT compiler, but just in case, GNAT GPL 2012 is an open source compiler available for Linux, Windows, and a few other platforms. (GNATPro is available for many platforms.)
Good luck, ask questions here, other resources include comp.lang.ada and the Ada sub-reddit.
EVEN is integer with the constraint of being, well, even. So the 2nd line is a constraint. But it will not be checked by the compiler -- and, to the best of my knowledge, the Anna toolset has never been able to check such constraints.
Anna is ancient and long gone -- but the recent Ada standard (Ada 2012) supports such annotations (which can even be checked by the compiler). So your Ada/Anna expression could be written in Ada 2012 as
subtype Even is Integer
with Dynamic_Predicate => Even mod 2 = 0;
This is actually an example from the Ada 2012 rationale, see Ada 2012.

Smart design of a math parser?

What is the smartest way to design a math parser? What I mean is a function that takes a math string (like: "2 + 3 / 2 + (2 * 5)") and returns the calculated value? I did write one in VB6 ages ago but it ended up being way to bloated and not very portable (or smart for that matter...). General ideas, psuedo code or real code is appreciated.
A pretty good approach would involve two steps. The first step involves converting the expression from infix to postfix (e.g. via Dijkstra's shunting yard) notation. Once that's done, it's pretty trivial to write a postfix evaluator.
I wrote a few blog posts about designing a math parser. There is a general introduction, basic knowledge about grammars, sample implementation written in Ruby and a test suite. Perhaps you will find these materials useful.
You have a couple of approaches. You could generate dynamic code and execute it in order to get the answer without needing to write much code. Just perform a search on runtime generated code in .NET and there are plenty of examples around.
Alternatively you could create an actual parser and generate a little parse tree that is then used to evaluate the expression. Again this is pretty simple for basic expressions. Check out codeplex as I believe they have a math parser on there. Or just look up BNF which will include examples. Any website introducing compiler concepts will include this as a basic example.
Codeplex Expression Evaluator
If you have an "always on" application, just post the math string to google and parse the result. Simple way but not sure if that's what you need - but smart in some way i guess.
I know this is old, but I came across this trying to develop a calculator as part of a larger app and ran across some issues using the accepted answer. The links were IMMENSELY helpful in understanding and solving this problem and should not be discounted. I was writing an Android app in Java and for each item in the expression "string," I actually stored a String in an ArrayList as the user types on the keypad. For the infix-to-postfix conversion, I iterated through each String in the ArrayList, then evaluated the newly arranged postfix ArrayList of Strings. This was fantastic for a small number of operands/operators, but longer calculations were consistently off, especially as the expressions started evaluating to non-integers. In the provided link for Infix to Postfix conversion, it suggests popping the Stack if the scanned item is an operator and the topStack item has a higher precedence. I found that this is almost correct. Popping the topStack item if it's precedence is higher OR EQUAL to the scanned operator finally made my calculations come out correct. Hopefully this will help anyone working on this problem, and thanks to Justin Poliey (and fas?) for providing some invaluable links.
The related question Equation (expression) parser with precedence? has some good information on how to get started with this as well.
-Adam
Assuming your input is an infix expression in string format, you could convert it to postfix and, using a pair of stacks: an operator stack and an operand stack, work the solution from there. You can find general algorithm information at the Wikipedia link.
ANTLR is a very nice LL(*) parser generator. I recommend it highly.
Developers always want to have a clean approach, and try to implement the parsing logic from ground up, usually ending up with the Dijkstra Shunting-Yard Algorithm. Result is neat looking code, but possibly ridden with bugs. I have developed such an API, JMEP, that does all that, but it took me years to have stable code.
Even with all that work, you can see even from that project page that I am seriously considering to switch over to using JavaCC or ANTLR, even after all that work already done.
11 years into the future from when this question was asked: If you don't want to re-invent the wheel, there are many exotic math parsers out there.
There is one that I wrote years ago which supports arithmetic operations, equation solving, differential calculus, integral calculus, basic statistics, function/formula definition, graphing, etc.
Its called ParserNG and its free.
Evaluating an expression is as simple as:
MathExpression expr = new MathExpression("(34+32)-44/(8+9(3+2))-22");
System.out.println("result: " + expr.solve());
result: 43.16981132075472
Or using variables and calculating simple expressions:
MathExpression expr = new MathExpression("r=3;P=2*pi*r;");
System.out.println("result: " + expr.getValue("P"));
Or using functions:
MathExpression expr = new MathExpression("f(x)=39*sin(x^2)+x^3*cos(x);f(3)");
System.out.println("result: " + expr.solve());
result: -10.65717648378352
Or to evaluate the derivative at a given point(Note it does symbolic differentiation(not numerical) behind the scenes, so the accuracy is not limited by the errors of numerical approximations):
MathExpression expr = new MathExpression("f(x)=x^3*ln(x); diff(f,3,1)");
System.out.println("result: " + expr.solve());
result: 38.66253179403897
Which differentiates x^3 * ln(x) once at x=3.
The number of times you can differentiate is 1 for now.
or for Numerical Integration:
MathExpression expr = new MathExpression("f(x)=2*x; intg(f,1,3)");
System.out.println("result: " + expr.solve());
result: 7.999999999998261... approx: 8
This parser is decently fast and has lots of other functionality.
Work has been concluded on porting it to Swift via bindings to Objective C and we have used it in graphing applications amongst other iterative use-cases.
DISCLAIMER: ParserNG is authored by me.

Resources