Hello. I urgently need a program in assembler, for a x86, in Linux.The program has to do the following:- Read from the keyboard a function of x. Example: "x+2-x^3*9" *) The function has to be in the form of dododod (d=digit [0-9], 0=operator [+,-,*,/,^]), *) Therefore, it does not admit 2 operators or 2 digits together (like "12^-x"), *) No error handling needed, it is assumed that the entered values are correct- Read from the keyboard the value of x. Example: "1"- Show the result of the function with that value of x (in the example it would be "-6")

I'm really newby to assembler programming so I would really preciate if someone could give me a hand "for the love of the game".

pushl $linefeed #push in the stack the string of linefeed pushl $t_str #push in the stack the data type call printf #print the linefeed addl $8,%esp #clear the stack

movl $3,%eax int $0x80 #call the interruption for printing

ret #this is the section where I want to parse char by char the input stored in the "function" variable, but I don't #know how. Then I would have to calculate the result of the function and show the output.

2) Which part's' are you having trouble with???I'm having trouble parsing the string of the formula input. I can't find the way to read character by character the string, to put the operands and the operators in a stack for the calculations. As you can see, I'm using AT&T notation and what I'm doing to compile the code is the following, in Red Hat: *) Open a terminal *) Go to the folder which contains the code *) Execute the next command "gcc -o "

3) Why the urgency if you are "new to assembly language"???The urgency is that my teacher is kinda crazy. He believes in the investigative capabilities of his students to solve any problem he can think of, while he does not have a clue of the assembly language. I'm in summer so the period of classes is really short and he gave us a week to get the project done.

Well.., there are plenty of algorithms for making an expression evaluator. Here is one of the simplest approaches:(assuming the conditions you have stated are preserved)

1) Get the expression (for example x+2-x^3*9).2) Get the value of 'x'.3) Construct new expression by converting any ASCII representation of a digit to it's binary form. Replace any occurrence of 'x' with appropriate value.

So from x+2-x^3*9 you will get something like this (hexadecimal representation):00000001 + 00000002 - 00000001 ^ 00000003 * 00000009

4) Search for operator with a higher mathematical precedence.5) Apply the operation on the nearby digits.6) Reconstruct the expression.7) Repeat last three steps

process_operation:;todo: check for ASCII values of "+-*/^..." in order (like a switch statement); Found-> Process that operation into an "order of operation" list; Not Found -> Fail/Exit (no error handling)

inc ebxjmp parse

Note that EBX *should* be BYTE aligned and hence on an "even address". So each "Digit" should be on an even BYTE address (dododo)... and each "Operation" should be on an odd BYTE address (dododo).

Just fill in the blanks with your own ideas on how to process ASCII code and the "order of operations" list.

Another thing I noticed with your code, is the unnecessary use of "pushl $t_str" in your printf routines. The strings are already in "%s" format (ASCII text with a null-terminator), so there is no need to add this extra step. You *do* need it for scanf though, as that is how the function defines the input.

mov eax, 1 #finalitation of the program mov ebx, 0 #finalitation of the program int 80h #finalitation of the program

ret

function resb 25 function resb 1

As you can see, I want to display the result of adding the first two digits entered in the function (just for testing purposes, in the main problem you aren't supposed to enter a digit followed by another). The problem is that when I enter in the function "12", it is displaying a "c" as te result of the sum (1+2=third letter from the alphabet -> c); when I enter "23", it is displaying an "e" as the result of the sum; etc etc. What am I doing wrong? What do I have to change to display the correct value?

Please study an ASCII Chart to understand what you are working with. You are confusing a string representation of a digit (ASCII) with a binary representation that a computer uses for mathematical operations.

If you notice the chart from the link above, '1'(31h) + '2'(32h) = 'c'(63h). As well as '2'(32h) + '3'(33h) = 'e'(65h).

This means you are not converting the ASCII Characters to Binary before performing mathematical operations, which was mentioned multiple times.

If you checked for a value between 30h and 39h (valid ASCII representation of numbers 0 through 9), and then subtracted 30h from that value... it would give you the converted binary number you need (i.e. '1'(31h) - "ASCII Digit Base"(30h) = 1(01h) ). In order to printf that number, you would simply add %i to the string (and the accompanying variable), and printf will automatically convert that Binary Digit 3(03h)/5(05h) back to an ASCII representation '3'(33h)/'5'(35h).

In short, you *really* need to study the differences between ASCII and Binary... or you will not make your deadline.

In order to help you on your way, I will post a generic "quick fix" (no error checking or optimization) of your code, study it until it "clicks"...