MIPS assembly language Write a program that takes in as a st

MIPS assembly language

Write a program that takes in, as a string, an expression in the Infix format and calculates its output. The program asks then the user for the next expression until the user hits the character ‘E’ which will terminate the program.

• Follow the stack implementation discussed in class: it is mandatory the explicit usage of the stack in your code.

• Make use of function calls whenever you see fit – functions must be present in your code.

• Numbers in expressions are multi-digit non-negative integers (but intermediate and final results can be negative integers); both numbers and the final result can all fit into a word.

• Operations can be +,-,* and /

Examples:

- Input: ((2-(8+9))*(1-4)) Output: 45

- Input: (7-(((6+2)–4)*8)) Output: -25

- Input: ((3*((205–102)+5))/(42–49)) Output: -46

Solution

Solution:

    .data
   disp:   .ascii \"\ Program to calculate fully parenthesize.\"
   Inread:   .asciiZ \"Enter the infix notation string.\"
   bufexp:    .space 200
   .text
   .global main
main:
   LA   $a0, disp
   LI   $vo, 4
   syscall
   LA   $a0, Inread
   LI $v0, 4
   syscall
   LI $t0, 0
   SUBU   $sp, $sp, 4
   SW   $t0, ($sp)
   LI   $t1, 0
LOOP:
   LB $t0, bufexp($t1)
   BEG $t0, 2, endofprg
   BEG $t0, 8, negchk
   BEG $t0, 9, num
   BEG   $t0, 1, calc
   BRE   $t0, 4, push
   ADD   $t1, $t1, 1
   jal LOOP
endprog:

MIPS assembly language Write a program that takes in, as a string, an expression in the Infix format and calculates its output. The program asks then the user f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site