If the calculator handles arithmetic precedence then the X register becomes a number stack and the pending operation register also becomes a stack. There are variations around this for the = key (a no-op), for example. If you then press another binary operator key then the X and Y registers are combined using the stored pending operator, the result is placed in the X register, the key press is stored as a new pending operator, and the Y register is reset to accept a new entry. If you press a binary operator key like + or * the value in the Y register is copied into the X register, the operation is stored, and the Y register is set to accept a new entry. When you enter a value it is shifted into the Y register. The X register is hidden and the Y register appears on the display. Traditional scientific calculators that respond immediately to key presses have an X and a Y register. BIG NOTE: If it hasn't seemed obvious I am trying to code in C language for PC just to get a working prototype and once I works will modify the code to work for embedded systems, hence why you see stdio.h and stdlib.h functions and console displays. I am looking into making the basic calculator and the hardware open source so that people that build their own scientific calculator, getting the input to work like a classical sceintific calculator would be the biggest breakthrough o f the project. I am at a loss here, if anyone could fill me in for some better topologies that would be great. this is what I have so far, minus the functions in other files that should be self explanatory:Ĭode: int main() obviously this code doesn't work, it pulls a zeros from the stack and adds that. The problem is because I am using a command line based system, I need to know what has happened previously, and I am in a rut that looks like in order to do so I have to use a whole gambit of flags and complicated logic that seems unnecessary. Keep in mind, the input is being done with a command terminal style setup where the code tests for the most recent input. There are a couple of rules I have to abide by: - I am using a stack to hold my numbers and math functions - The stack should be kept as small as possible and only parenthesis require more than two items on the stack - math functions such as + - * / should act as an = but remembers to do math to the next new number The last one is what makes things confusing, because I am trying to make a calculator that operates like a standard scientific calculator or just a standard calculator when you type 1 + 2 and then press + again, it computes the previous equation to 3 the instant you hit the second +, but remembers that it is adding the following number about to be input. The basic operation of a scientific calculator is extremely complicated.and as I have discovered very convoluted. Last semester in my programming class we built an RPN calculator in java and my professor made mention that an algebraic calculator would be difficult to make, I scoffed at that until just yesterday. I have been in the process of using an ATMega2560 to make a physically functioning programmable scientific calculator. Not so much hardware related but related to an AVR project that I am working on.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |