Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HOMEWORK 8 Due on 06/27/2015 before 8:00 AM INTRODUCTION: In Reverse Polish(post

ID: 3685516 • Letter: H

Question

HOMEWORK 8 Due on 06/27/2015 before 8:00 AM INTRODUCTION: In Reverse Polish(postfix) notation the operators follow their operands; for instance, to add three and four one would write "3 4+" rather than "3+ 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 -45" in conventional infix notation would be written "3 4-5+" in RPN: first subtract 4 from 3, then add 5 to that. An advantage of RPN is that it obviates the need for parentheses that are required by infix. While "3-4+ 5" can also be written "(3 - 4)+5", that means something quite different from "3 (4+ 5)", and only the parentheses disambiguate the two meanings. In postfix, the latter would be written "3 45+ ", which unambiguously means "3 (4 5 )". Interpreters of Reverse Polish notation are stack-based; that is, operands are pushed onto a stack, and when an operation is performed, its operands are popped from a stack and its result pushed back on. Stacks, and therefore RPN, have the advantage of being easy to implement and very fast Please complete the implementation of the two functions given in the questions section below Test your functions using the main program given. After you complete the homework rename the file "HW8_AssemblyFunctions.S" to "HW8_yourredID.S" and submit only this file on blackboard. Do not include main.c or add contents of main.c to this file. QUESTION 1: Write a function to convert a given function from infix to postfix in assembly. The basic structure of the function is given in the attached assembly language file QUESTION 2: Write a function to convert a given function from postfix to infix in assembly language. The basic structure of the function is given in the attached assembly language file

Explanation / Answer

Can help u with this:

.globl _toPostfix
_toPostfix:

pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%ebx
movl 12(%ebp),%eax
xorl %esi,%esi
xorl %edi,%edi
xorl %ecx,%ecx
loop:
cmpl $0x0,(%ebx,%esi,1)
je miniloop2
cmpl $0x2A, (%ebx,%esi,1)
je checkmultdiv
cmpl $0x2F, (%ebx,%esi,1)
jne addsubcheck

checkmultdiv:
cmpl $0x2A,4(%esp)
je removeone
cmpl $0x2F,4(%esp)
jne pushtostack
removeone:
movl 4(%esp),%edx
movl %edx,(%eax,%edi,1)
xorl %edx,%edx
popl %esp
decl %ecx
incl %edi

pushtostack:
pushl (%ebx,%esi,1)
incl %ecx
jmp incrementi

addsubcheck:
cmpl $0x2B,(%ebx,%esi,1)
je removesome
cmpl $0x2D,(%ebx,%esi,1)
jne openparencheck

removesome:
cmpl $0,%ecx
je pushtostack
cmpl $0x28, 4(%esp)
je pushtostack
movl 4(%esp),%edx
movl %edx,(%eax,%edi,1)
xor %edx,%edx
decl %ecx
incl %edi
jmp removesome

openparencheck:
cmpl $0x28,(%ebx,%esi,1)
jne closeparencheck
jmp pushtostack

closeparencheck:
cmpl $0x29, (%ebx,%esi,1)
jne pushtopost

miniloop:
cmpl $0x28,4(%esp)
je decrements
movl 4(%esp),%edx
movl %edx,(%eax,%edi,1)
xor %edx,%edx
decl %ecx
incl %edi
jmp miniloop

decrements:
decl %ecx
jmp incrementi

pushtopost:
movl (%ebx,%esi,1),%edx
movl %edx,(%eax,%edi,1)
incl %edi

incrementi:
incl %esi
jmp loop

miniloop2:
cmp $0,%ecx
je out
movl 4(%esp),%edx
movl %edx,(%eax,%edi,1)
xorl %edx,%edx
decl %ecx
incl %edi

out:
popl %ebp
ret