Question in polish Notation. example:
infix notation : (1+5)*(8-(4-1))
postix notation : 15+841--*
Given a consant string
: 1. Write just the function in C and the whole program in MIPS assembly that converts with the help of stack, the given string and makes it postfix. Then write another function in C and then the program in MIPS assembly that calculates the result of the converted(postix) function.
The function to convert infix to postfix in C.
int infixToPostfix(char* exp)
{
int i, k;
struct Stack* stack = createStack(strlen(exp));
if(!stack)
return -1 ;
for (i = 0, k = -1; exp[i]; ++i)
{
if (isOperand(exp[i]))
exp[++k] = exp[i];
else if (exp[i] == '(')
push(stack, exp[i]);
else if (exp[i] == ')')
{
while (!isEmpty(stack) && peek(stack) != '(')
exp[++k] = pop(stack);
if (!isEmpty(stack) && peek(stack) != '(')
return -1;
else
pop(stack);
}
else
{
while (!isEmpty(stack) && Prec(exp[i]) <=
Prec(peek(stack)))
exp[++k] = pop(stack);
push(stack, exp[i]);
}
}
while (!isEmpty(stack))
exp[++k] = pop(stack );
exp[++k] = '\0';
printf( "%s\n", exp );
}
C program to evaluate postfix expression,with Push and Pop with
their usual meanings
void EvalPostfix()
{
char pofx[50],ch;
int i=0,op1,op2;
printf("\n\nEnter Postfix Expression : ");
scanf("%s",pofx);
while( (ch=pofx[i++]) != '\0')
{
if(isdigit(ch)) push(ch-'0');
else
{
op2=pop();
op1=pop();
switch(ch)
{
case '+':push(op1+op2);break;
case '-':push(op1-op2);break;
case '*':push(op1*op2);break;
case '/':push(op1/op2);break;
}
}
}
printf("\n Given Postfix Expression: %s\n",pofx);
printf("\n Result after Evaluation: %d\n",s[top]);
}
The exact program in MIPS for Postfix Evaluation would look like
below
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.globl s
.section .bss,"aw",@nobits
.align 2
.type s, @object
.size s, 200
s:
.space 200
.globl top
.data
.align 2
.type top, @object
.size top, 4
top:
.word -1
.text
.align 2
.globl _Z4pushi
$LFB0 = .
.set nomips16
.ent _Z4pushi
.type _Z4pushi, @function
_Z4pushi:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-8
$LCFI0:
sw $fp,4($sp)
$LCFI1:
move $fp,$sp
movz $31,$31,$0
$LCFI2:
sw $4,8($fp)
lw $2,%got(top)($28)
nop
lw $2,0($2)
nop
addiu $3,$2,1
lw $2,%got(top)($28)
nop
sw $3,0($2)
lw $2,%got(top)($28)
nop
lw $2,0($2)
lw $3,%got(s)($28)
sll $2,$2,2
addu $2,$3,$2
lw $3,8($fp)
nop
sw $3,0($2)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z4pushi
$LFE0:
.size _Z4pushi, .-_Z4pushi
.align 2
.globl _Z3popv
$LFB1 = .
.set nomips16
.ent _Z3popv
.type _Z3popv, @function
_Z3popv:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-8
$LCFI3:
sw $fp,4($sp)
$LCFI4:
move $fp,$sp
movz $31,$31,$0
$LCFI5:
lw $2,%got(top)($28)
nop
lw $2,0($2)
lw $4,%got(s)($28)
sll $3,$2,2
addu $3,$4,$3
lw $3,0($3)
addiu $4,$2,-1
lw $2,%got(top)($28)
nop
sw $4,0($2)
move $2,$3
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z3popv
$LFE1:
.size _Z3popv, .-_Z3popv
.rdata
.align 2
$LC0:
.ascii "\012\012Enter Postfix Expression : \000"
.align 2
$LC1:
.ascii "%s\000"
.align 2
$LC2:
.ascii "\012 Given Postfix Expression: %s\012\000"
.align 2
$LC3:
.ascii "\012 Result after Evaluation: %d\012\000"
.text
.align 2
.globl main
$LFB2 = .
.set nomips16
.ent main
.type main, @function
main:
.frame $fp,104,$31 # vars= 72, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-104
$LCFI6:
sw $31,100($sp)
$LCFI7:
sw $fp,96($sp)
movz $31,$31,$0
$LCFI8:
move $fp,$sp
$LCFI9:
.cprestore 16
sw $0,32($fp)
lw $2,%got($LC0)($28)
nop
addiu $4,$2,%lo($LC0)
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$fp,40
lw $3,%got($LC1)($28)
nop
addiu $4,$3,%lo($LC1)
move $5,$2
lw $2,%call16(scanf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L6
nop
$L13:
lb $2,36($fp)
nop
addiu $2,$2,-48
sltu $2,$2,10
beq $2,$0,$L7
nop
lb $2,36($fp)
nop
addiu $2,$2,-48
move $4,$2
lw $2,%got(_Z4pushi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L6
nop
$L7:
lw $2,%got(_Z3popv)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $2,24($fp)
lw $2,%got(_Z3popv)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $2,28($fp)
lb $2,36($fp)
li $3,43 # 0x2b
beq $2,$3,$L9
nop
slt $3,$2,44
beq $3,$0,$L12
nop
li $3,42 # 0x2a
beq $2,$3,$L8
nop
b $L6
nop
$L12:
li $3,45 # 0x2d
beq $2,$3,$L10
nop
li $3,47 # 0x2f
beq $2,$3,$L11
nop
b $L6
nop
$L9:
lw $3,28($fp)
lw $2,24($fp)
nop
addu $2,$3,$2
move $4,$2
lw $2,%got(_Z4pushi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L6
nop
$L10:
lw $3,28($fp)
lw $2,24($fp)
nop
subu $2,$3,$2
move $4,$2
lw $2,%got(_Z4pushi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L6
nop
$L8:
lw $3,28($fp)
lw $2,24($fp)
nop
mult $3,$2
mflo $2
move $4,$2
lw $2,%got(_Z4pushi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L6
nop
$L11:
lw $3,28($fp)
lw $2,24($fp)
nop
bne $2,$0,1f
div $0,$3,$2
break 7
1:
mfhi $3
mflo $2
move $4,$2
lw $2,%got(_Z4pushi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
$L6:
lw $2,32($fp)
addiu $3,$fp,24
addu $2,$3,$2
lbu $2,16($2)
nop
sb $2,36($fp)
lb $2,36($fp)
nop
sltu $2,$0,$2
andi $2,$2,0x00ff
lw $3,32($fp)
nop
addiu $3,$3,1
sw $3,32($fp)
bne $2,$0,$L13
nop
addiu $2,$fp,40
lw $3,%got($LC2)($28)
nop
addiu $4,$3,%lo($LC2)
move $5,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
nop
lw $2,%got(top)($28)
nop
lw $2,0($2)
lw $3,%got(s)($28)
sll $2,$2,2
addu $2,$3,$2
lw $2,0($2)
lw $3,%got($LC3)($28)
nop
addiu $4,$3,%lo($LC3)
move $5,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $2,$0
move $sp,$fp
lw $31,100($sp)
lw $fp,96($sp)
addiu $sp,$sp,104
j $31
nop
.set macro
.set reorder
.end main
$LFE2:
.size main, .-main
.section .eh_frame,"aw",@progbits
$Lframe1:
.4byte $LECIE1-$LSCIE1
$LSCIE1:
.4byte 0x0
.byte 0x1
.globl __gxx_personality_v0
.ascii "zP\000"
.uleb128 0x1
.sleb128 -4
.byte 0x1f
.uleb128 0x5
.byte 0x0
.4byte __gxx_personality_v0
.byte 0xc
.uleb128 0x1d
.uleb128 0x0
.align 2
$LECIE1:
$LSFDE5:
.4byte $LEFDE5-$LASFDE5
$LASFDE5:
.4byte $LASFDE5-$Lframe1
.4byte $LFB2
.4byte $LFE2-$LFB2
.uleb128 0x0
.byte 0x4
.4byte $LCFI6-$LFB2
.byte 0xe
.uleb128 0x68
.byte 0x4
.4byte $LCFI8-$LCFI6
.byte 0x11
.uleb128 0x1e
.sleb128 2
.byte 0x11
.uleb128 0x1f
.sleb128 1
.byte 0x4
.4byte $LCFI9-$LCFI8
.byte 0xd
.uleb128 0x1e
.align 2
$LEFDE5:
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
And that for conversion from infix to postfix would as below
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.text
.align 2
.globl _Z11createStackj
$LFB0 = .
.set nomips16
.ent _Z11createStackj
.type _Z11createStackj, @function
_Z11createStackj:
.frame $fp,40,$31 # vars= 8, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-40
$LCFI0:
sw $31,36($sp)
$LCFI1:
sw $fp,32($sp)
movz $31,$31,$0
$LCFI2:
move $fp,$sp
$LCFI3:
.cprestore 16
sw $4,40($fp)
li $4,12 # 0xc
lw $2,%call16(malloc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $2,24($fp)
lw $2,24($fp)
nop
bne $2,$0,$L2
nop
move $2,$0
b $L3
nop
$L2:
lw $2,24($fp)
li $3,-1 # 0xffffffffffffffff
sw $3,0($2)
lw $2,24($fp)
lw $3,40($fp)
nop
sw $3,4($2)
lw $2,24($fp)
nop
lw $2,4($2)
nop
sll $2,$2,2
move $4,$2
lw $2,%call16(malloc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $3,$2
lw $2,24($fp)
nop
sw $3,8($2)
lw $2,24($fp)
nop
lw $2,8($2)
nop
bne $2,$0,$L4
nop
move $2,$0
b $L3
nop
$L4:
lw $2,24($fp)
$L3:
move $sp,$fp
lw $31,36($sp)
lw $fp,32($sp)
addiu $sp,$sp,40
j $31
nop
.set macro
.set reorder
.end _Z11createStackj
$LFE0:
.size _Z11createStackj, .-_Z11createStackj
.align 2
.globl _Z7isEmptyP5Stack
$LFB1 = .
.set nomips16
.ent _Z7isEmptyP5Stack
.type _Z7isEmptyP5Stack, @function
_Z7isEmptyP5Stack:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI4:
sw $fp,4($sp)
$LCFI5:
move $fp,$sp
movz $31,$31,$0
$LCFI6:
sw $4,8($fp)
lw $2,8($fp)
nop
lw $2,0($2)
nop
addiu $2,$2,1
sltu $2,$2,1
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z7isEmptyP5Stack
$LFE1:
.size _Z7isEmptyP5Stack, .-_Z7isEmptyP5Stack
.align 2
.globl _Z4peekP5Stack
$LFB2 = .
.set nomips16
.ent _Z4peekP5Stack
.type _Z4peekP5Stack, @function
_Z4peekP5Stack:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI7:
sw $fp,4($sp)
$LCFI8:
move $fp,$sp
movz $31,$31,$0
$LCFI9:
sw $4,8($fp)
lw $2,8($fp)
nop
lw $3,8($2)
lw $2,8($fp)
nop
lw $2,0($2)
nop
sll $2,$2,2
addu $2,$3,$2
lw $2,0($2)
nop
sll $2,$2,24
sra $2,$2,24
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z4peekP5Stack
$LFE2:
.size _Z4peekP5Stack, .-_Z4peekP5Stack
.align 2
.globl _Z3popP5Stack
$LFB3 = .
.set nomips16
.ent _Z3popP5Stack
.type _Z3popP5Stack, @function
_Z3popP5Stack:
.frame $fp,32,$31 # vars= 0, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-32
$LCFI10:
sw $31,28($sp)
$LCFI11:
sw $fp,24($sp)
movz $31,$31,$0
$LCFI12:
move $fp,$sp
$LCFI13:
.cprestore 16
sw $4,32($fp)
lw $4,32($fp)
lw $2,%got(_Z7isEmptyP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sltu $2,$2,1
andi $2,$2,0x00ff
beq $2,$0,$L11
nop
lw $2,32($fp)
nop
lw $4,8($2)
lw $2,32($fp)
nop
lw $3,0($2)
nop
move $2,$3
sll $2,$2,2
addu $2,$4,$2
lw $2,0($2)
nop
sll $2,$2,24
sra $2,$2,24
addiu $4,$3,-1
lw $3,32($fp)
nop
sw $4,0($3)
b $L12
nop
$L11:
li $2,36 # 0x24
$L12:
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
.set macro
.set reorder
.end _Z3popP5Stack
$LFE3:
.size _Z3popP5Stack, .-_Z3popP5Stack
.align 2
.globl _Z4pushP5Stackc
$LFB4 = .
.set nomips16
.ent _Z4pushP5Stackc
.type _Z4pushP5Stackc, @function
_Z4pushP5Stackc:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI14:
sw $fp,4($sp)
$LCFI15:
move $fp,$sp
movz $31,$31,$0
$LCFI16:
sw $4,8($fp)
move $2,$5
sb $2,12($fp)
lw $2,8($fp)
nop
lw $3,8($2)
lw $2,8($fp)
nop
lw $2,0($2)
nop
addiu $4,$2,1
lw $2,8($fp)
nop
sw $4,0($2)
lw $2,8($fp)
nop
lw $2,0($2)
nop
sll $2,$2,2
addu $2,$3,$2
lb $3,12($fp)
nop
sw $3,0($2)
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z4pushP5Stackc
$LFE4:
.size _Z4pushP5Stackc, .-_Z4pushP5Stackc
.align 2
.globl _Z9isOperandc
$LFB5 = .
.set nomips16
.ent _Z9isOperandc
.type _Z9isOperandc, @function
_Z9isOperandc:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI17:
sw $fp,4($sp)
$LCFI18:
move $fp,$sp
movz $31,$31,$0
$LCFI19:
move $2,$4
sb $2,8($fp)
lb $2,8($fp)
nop
slt $2,$2,97
bne $2,$0,$L17
nop
lb $2,8($fp)
nop
slt $2,$2,123
bne $2,$0,$L18
nop
$L17:
lb $2,8($fp)
nop
slt $2,$2,65
bne $2,$0,$L19
nop
lb $2,8($fp)
nop
slt $2,$2,91
beq $2,$0,$L19
nop
$L18:
li $2,1 # 0x1
b $L20
nop
$L19:
move $2,$0
$L20:
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z9isOperandc
$LFE5:
.size _Z9isOperandc, .-_Z9isOperandc
.align 2
.globl _Z4Precc
$LFB6 = .
.set nomips16
.ent _Z4Precc
.type _Z4Precc, @function
_Z4Precc:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI20:
sw $fp,4($sp)
$LCFI21:
move $fp,$sp
movz $31,$31,$0
$LCFI22:
move $2,$4
sb $2,8($fp)
lb $2,8($fp)
li $3,45 # 0x2d
beq $2,$3,$L25
nop
slt $3,$2,46
beq $3,$0,$L27
nop
li $3,42 # 0x2a
beq $2,$3,$L24
nop
li $3,43 # 0x2b
beq $2,$3,$L25
nop
b $L23
nop
$L27:
li $3,47 # 0x2f
beq $2,$3,$L24
nop
li $3,94 # 0x5e
beq $2,$3,$L26
nop
b $L23
nop
$L25:
li $2,1 # 0x1
b $L28
nop
$L24:
li $2,2 # 0x2
b $L28
nop
$L26:
li $2,3 # 0x3
b $L28
nop
$L23:
li $2,-1 # 0xffffffffffffffff
$L28:
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z4Precc
$LFE6:
.size _Z4Precc, .-_Z4Precc
.align 2
.globl _Z14infixToPostfixPc
$LFB7 = .
.set nomips16
.ent _Z14infixToPostfixPc
.type _Z14infixToPostfixPc, @function
_Z14infixToPostfixPc:
.frame $fp,56,$31 # vars= 16, regs= 3/0, args= 16, gp= 8
.mask 0xc0010000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-56
$LCFI23:
sw $31,52($sp)
$LCFI24:
sw $fp,48($sp)
movz $31,$31,$0
$LCFI25:
sw $16,44($sp)
$LCFI26:
move $fp,$sp
$LCFI27:
.cprestore 16
sw $4,56($fp)
lw $4,56($fp)
lw $2,%call16(strlen)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $4,$2
lw $2,%got(_Z11createStackj)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $2,24($fp)
lw $2,24($fp)
nop
bne $2,$0,$L31
nop
li $2,-1 # 0xffffffffffffffff
b $L32
nop
$L31:
sw $0,32($fp)
li $2,-1 # 0xffffffffffffffff
sw $2,28($fp)
b $L33
nop
$L49:
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $2,0($2)
nop
move $4,$2
lw $2,%got(_Z9isOperandc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sltu $2,$0,$2
andi $2,$2,0x00ff
beq $2,$0,$L34
nop
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
lw $2,28($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lw $3,32($fp)
lw $4,56($fp)
nop
addu $3,$4,$3
lb $3,0($3)
nop
sb $3,0($2)
b $L35
nop
$L34:
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $3,0($2)
li $2,40 # 0x28
bne $3,$2,$L36
nop
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $2,0($2)
lw $4,24($fp)
move $5,$2
lw $2,%got(_Z4pushP5Stackc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L35
nop
$L36:
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $3,0($2)
li $2,41 # 0x29
bne $3,$2,$L45
nop
b $L38
nop
$L41:
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
lw $2,28($fp)
lw $3,56($fp)
nop
addu $16,$3,$2
lw $4,24($fp)
lw $2,%got(_Z3popP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sb $2,0($16)
$L38:
lw $4,24($fp)
lw $2,%got(_Z7isEmptyP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
bne $2,$0,$L39
nop
lw $4,24($fp)
lw $2,%got(_Z4peekP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $3,$2
li $2,40 # 0x28
beq $3,$2,$L39
nop
li $2,1 # 0x1
b $L40
nop
$L39:
move $2,$0
$L40:
bne $2,$0,$L41
nop
lw $4,24($fp)
lw $2,%got(_Z7isEmptyP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
bne $2,$0,$L42
nop
lw $4,24($fp)
lw $2,%got(_Z4peekP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $3,$2
li $2,40 # 0x28
beq $3,$2,$L42
nop
li $2,1 # 0x1
b $L43
nop
$L42:
move $2,$0
$L43:
beq $2,$0,$L44
nop
li $2,-1 # 0xffffffffffffffff
b $L32
nop
$L44:
lw $4,24($fp)
lw $2,%got(_Z3popP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
b $L35
nop
$L48:
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
lw $2,28($fp)
lw $3,56($fp)
nop
addu $16,$3,$2
lw $4,24($fp)
lw $2,%got(_Z3popP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sb $2,0($16)
$L45:
lw $4,24($fp)
lw $2,%got(_Z7isEmptyP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
bne $2,$0,$L46
nop
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $2,0($2)
nop
move $4,$2
lw $2,%got(_Z4Precc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $16,$2
lw $4,24($fp)
lw $2,%got(_Z4peekP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $4,$2
lw $2,%got(_Z4Precc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
slt $2,$2,$16
bne $2,$0,$L46
nop
li $2,1 # 0x1
b $L47
nop
$L46:
move $2,$0
$L47:
bne $2,$0,$L48
nop
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $2,0($2)
lw $4,24($fp)
move $5,$2
lw $2,%got(_Z4pushP5Stackc)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
$L35:
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
$L33:
lw $2,32($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
lb $2,0($2)
nop
sltu $2,$0,$2
andi $2,$2,0x00ff
bne $2,$0,$L49
nop
b $L50
nop
$L51:
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
lw $2,28($fp)
lw $3,56($fp)
nop
addu $16,$3,$2
lw $4,24($fp)
lw $2,%got(_Z3popP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sb $2,0($16)
$L50:
lw $4,24($fp)
lw $2,%got(_Z7isEmptyP5Stack)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sltu $2,$2,1
andi $2,$2,0x00ff
bne $2,$0,$L51
nop
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
lw $2,28($fp)
lw $3,56($fp)
nop
addu $2,$3,$2
sb $0,0($2)
lw $4,56($fp)
lw $2,%call16(puts)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $2,$0
$L32:
move $sp,$fp
lw $31,52($sp)
lw $fp,48($sp)
lw $16,44($sp)
addiu $sp,$sp,56
j $31
nop
.set macro
.set reorder
.end _Z14infixToPostfixPc
$LFE7:
.size _Z14infixToPostfixPc, .-_Z14infixToPostfixPc
.section .eh_frame,"aw",@progbits
$Lframe1:
.4byte $LECIE1-$LSCIE1
$LSCIE1:
.4byte 0x0
.byte 0x1
.globl __gxx_personality_v0
.ascii "zP\000"
.uleb128 0x1
.sleb128 -4
.byte 0x1f
.uleb128 0x5
.byte 0x0
.4byte __gxx_personality_v0
.byte 0xc
.uleb128 0x1d
.uleb128 0x0
.align 2
$LECIE1:
$LSFDE15:
.4byte $LEFDE15-$LASFDE15
$LASFDE15:
.4byte $LASFDE15-$Lframe1
.4byte $LFB7
.4byte $LFE7-$LFB7
.uleb128 0x0
.byte 0x4
.4byte $LCFI23-$LFB7
.byte 0xe
.uleb128 0x38
.byte 0x4
.4byte $LCFI26-$LCFI23
.byte 0x11
.uleb128 0x10
.sleb128 3
.byte 0x11
.uleb128 0x1e
.sleb128 2
.byte 0x11
.uleb128 0x1f
.sleb128 1
.byte 0x4
.4byte $LCFI27-$LCFI26
.byte 0xd
.uleb128 0x1e
.align 2
$LEFDE15:
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
You can also convert any C program to it's assembly equivalent (Whether MIPS or x86) using compiler flags -S on G++.
Question in polish Notation. example: infix notation : (1+5)*(8-(4-1)) postix notation : 15+841--* Given a consant...
Write a program to convert an expression written in infix notation to be converted to postfix notation. The program must do the following: a. Read a string of characters representing an expression in infix notation. The '$' is to be added at the end of the string to mark its ending. Each character is a letter, digit, +,-,*, or /. If a character is any other character an error must be signaled and the program is terminated b. Use stacks...
Python Issue Postfix notation (also known as Reverse Polish Notation or RPN in short) is a mathematical notation in which operators follow all of its operands. It is different from infix notation in which operators are placed between its operands. The algorithm to evaluate any postfix expression is based on stack and is pretty simple: Initialize empty stack For every token in the postfix expression (scanned from left to right): If the token is an operand (number), push it on...
Write the reverse Polish notation, the infix notation and the result of the pseudocode given below. Show the floating-point register stack after each instruction. The first two instructions are given. FLD 2 FLD 4 FLD 2 FDIV FADD FLD 5 FLD 25 FSQRT FDIV FMUL FLD 5 FADD FLD 1 FADD FLD 2 FDIV
QUESTION 13 Convert (8 – 5) / 2 expression from infix to reverse Polish (postfix) notation A. 0.5*(8-5) B. -85/2 C. 8 5 – 2 / D. /2 – 85
QUESTION 9 Convert (8 – 5) / 2 expression from infix to reverse Polish (postfix) notation A. 0.5*(8-5) B. -85/2 C. 8 5 – 2 / D. /2 – 85
We as humans write math expression in infix notation, e.g. 5 + 2 (the operators are written in-between the operands). In a computer’s language, however, it is preferred to have the operators on the right side of the operands, i.e. 5 2 +. For more complex expressions that include parenthesis and multiple operators, a compiler has to convert the expression into postfix first and then evaluate the resulting postfix. Write a program that takes an “infix” expression as input, uses...
Write a java program for the following: Your program reads an infix expression represented by a string S from the standard input (the keyboard). Then your program converts the infix expression into a postfix expression P using the algorithm. Next, your program evaluates the postfix expression P to produce a single result R. At last, your program displays the original infix expression S, the corresponding postfix expression P and the final result R on the standard output ( the screen...
Using ADT Stack: Evaluating infix expressions by converting them to postfix expressions Postfix notation: In a postfix expression, a binary operation follows its two opperands. The order of the operands in a infix expression is the same as in the corresponding postfix expression but the order of the operators might change based on the precedence of the operators and the existing of paranthses. Infix Postfix a + b a b + (a + b) * c a b + c...
You are to write a program that implements a Reverse Polish Notation Calculator in C using BISON and FLEX, You only have to edit the BISON and FLEX files. Link to the files to start and have a general view of the program: https://www.dropbox.com/sh/83yzs66jhftqj5b/AABZcY9Qwl84JdUFnYpQaZk9a?dl=0 Reverse Polish Notation is a mathematical notation in which every operator follows all of its operands. It is sometimes called postfix notation, and does not require any parentheses as long as each operator has a fixed...
You are to write a program name expressionTree.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) One alphabetic character - "x" (representing a value to be supplied later). (3) Binary operators (+, -, *, / and % (modulo)). (4) Parentheses You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract...