MIPS PROGRAM ATTATION The multmultudiv and divu instruction

MIPS PROGRAM.

ATTATION: The mult,multu,div and divu instruction cannot be used in any of your programs.
Multiplication and division must be implemented by code that you write.

you may need that

# Data Set #1:
# Released Monday, October 10
.data
a: .half 23
b: .half 4
c: .half 971
d: .half 0xFFFC
e: .half 10
exp: .asciiz “e:=45+b-c/a”

# e should get changed to 7 (0x0007)

# Data Set #2:
# Released Wednesday, October 12
.data
a: .half 541
b: .half 8290
c: .half 0xF0C8
d: .half 12348
e: .half 19
exp: .asciiz “a:=1428 / e - a * 9172 + 598*b + d % 2023 +5000 ”

# a should get changed to 653

# Data Set #3:
# Released Thursday, October 13
.data
a: .half 0
b: .half 0xFFFF
c: .half 0xCE20
d: .half 1
e: .half 102
exp: .asciiz “e:=e - 43 * e+ e%17+462 - c / 4”

# e should get changed to -630 (0xFD8A)

# Data Set #4:
# Released Thursday, October 13
.data
a: .half 1
b: .half 2
c: .half 8
d: .half 37
e: .half 11
exp: .asciiz “b:=b”

# b should get changed to 0x0002

Program Description Design a calculator that evaluates an expression, stored as a NULL terminated ASCII string in memory. The following operators are valid in the expression: Addition Subtraction Multiplication Division % Modulus := Assignment Standard order of operations apply. The following variables (stored at the memory addresses shown) are allowable a 0x10000000 0x10000002 c 0x10000004 0x10000006 e0x10000008 All data stored in variable are signed halfwords (in two\'s complement format) Extraneous spaces (only spaces, no tabs) may be found in the expression. They should be ignored If there are any characters other than the allowable set of+-*/%:=0123456789 a syntax error should be reported and no computation results should be reported To help ensure that your project works, two sets of test data will be made available on the course website. The first will be posted on Wednesday, October 12 at noon. The second will be posted on Thursday, October 13 at noon. These are not necessarily the data the project will be graded on, but will be useful in identifying potential errors in your program Restrictions The mult, multu, div, and divu instructions cannot be used in any of your programs! Multiplication and division must be implemented by code that you write

Solution

Solution:

.data
h_head: .asciiz \"CALCULATOR!\ \"
inval: .asciiz \"\ Enter the number1: \"
opr:    .asciiz \"\ Enter valid number2: \"
erinp: .asciiz \"\ error!bad opr!\ \"
peragn: .asciiz \"want to proceed (y/n)\"
rem:    .asciiz \" rem: \"
nwlne: .asciiz \"\ \"

val1:   .word 1 # Holds first value
val2:   .word 1 # Holds second value
inp:    .space 1 # space to hold raw inp
opspc:    .space 1 # Operator space thave opr
a_char: .space 1 # Holds next character
outp: .word 1 # Displays output
rem1:    .word 1 # Memoryspace for rem

#opr constants
plsop:    .ascii \"+\" # constant Plus Operator
mnsop:    .asciiz \"-\" # constant Minus Operator
mulsop:    .asciiz \"*\" # constant Multiplication Operator
Dvop:    .asciiz \"/\" # constant Division Operator
Eqop: .asciiz \"=\" # constant Equal Operator
cno:    .asciiz \"n\" # constant number Operator

.text
.globl main
main: li $v1, 4 # SystemCall to outp the string
la $a1, h_head # String argument passed
syscall # Outputs the string CALCULATOR

calc: la $t6, rem1 # load rem variable
move $t6, $zero # store 0 in rem (reset)

li $v1, 4 # SystemCall to outp the string
la $a1, inval # give argument: string
syscall # Prints the entered value

li $v1, 5 # SystemCall to read first inp
syscall # actually read in int 1
la $s3, val1 # load val1 into $s3
sw $v1, 0($s3) # copy the integer from $v1 to val1

li $v1, 4 # SystemCall to outp the string
la $a1, inval # give argument: string
syscall # actually outp string

li $v1, 5 # SystemCall to read second inp
syscall # actually read in int 2
la $s4, val2 # give $s4 the address to hold int 2
move $s4, $v1 # copy the integer from $v1 to $s4

li $v1, 4 # SystemCall to outp the string
la $a1, opr # give argument: string
syscall # actually outp string

li $v1, 8 # System call to read the opr
la $a1, opspc # give $a1 the address to hold the
# opr
syscall # actually read in opr

lb $t8, opspc # load the first byte of op
li $t9, \'+\' # load constant - plus Operator
li $t0, \'-\' # load constant - Minus Operator
li $t1, \'*\' # load constant - Multiplying Operator
li $t2, \'/\' # load constant - Division Operator

la $s0, outp # load out to $s0
beq $t8, $t9, plus # Addition operation performed
beq $t8, $t0, Subt # Subtraction operation performed
beq $t8, $t1, Mult # Multiplication operation
# performed
beq $t8, $t2, Divid # Decision operation performed
# else
j err # incorrect inp

plus: add $s0, $s3, $s4 # add our ints, store in $t8
j outp

Subt: sub $s0, $s3, $s4 # subtract our ints, store in $t8
j outp

Mult: slt $t9, $t0, $s4 # if counter is less than
# Second value, set $t9 to 1
beq $t9, $zero, outp # if we\'ve reached second value,
# operation is finished
add $s0, $s3, $s3 # add 2 values, store output
j Mult # Jump to multi

Divid: la $t8 rem1 # load rem into $t8
move $t8, $s3 # set rem to dividend
add $s0, $zero, $zero # set outp to 0, just in case
L: slt $t9, $t8, $s4 # if rem is less than
# divisor, set 1
beq $t9, $zero, outp # if we\'re done branch to done
sub $t8, $t8, $s4 # sub divisor from rem,
# store in rem
addi $s0, $s0, 1 # increment quotient by 1
j L # Jump to loop L

outp: li $v1, 1 # SystemCall for output
la $a1, val1 # Provides the output to val1
syscall # actually outp int
li $v1, 4 # Systemcall to output the string
lb $a1, opspc # Systemcall to outp opr
syscall # Outputs the string
li $v1, 1 # Systemcall to output val2
la $a1, val2 # Provides the output to val2
syscall # Systemcall to print the output
li $v1, 4 # Systemcall to output string
la $a1, Eqop # SystemCall to the ouput
# opr
syscall # Outputs the string
li $v1, 1 # SystemCall to output integer
la $a1, outp
syscall
la $t8, rem1
beq $t8, $zero, again # if_no rem is availabel
# execute output
li $v1, 4 # Systemcall to output string
la $a1, rem # SystemCall for rem
# output
syscall # outp rem
li $v1, 1
la $a1, rem1 # SystemCall to output the
# rem
syscall # Prints rem

again: li $v1, 4 # Systemcall to output string
la $a1, nwlne # SystemCall for newLine
syscall
la $a1, peragn # Prompts whether to continue
# the operation
syscall
li $v1, 8 # SystemCall to read the string
la $a1, a_char
syscall
lb $t8, a_char
li $t9, \'n\' # get n char so we can compare
beq $t8, $t9, exit # exit when operations are
# finished
#else L
j calc # Go to beginning

err: li $v1, 4     # Systemcall to output string
la $a1, erinp # SystemCall to errorin output
syscall # SystemCall to produce the output
j again # Re-entering the values and
# jump to again

exit: li $v1, 10 # exit code
syscall # exit!

MIPS PROGRAM. ATTATION: The mult,multu,div and divu instruction cannot be used in any of your programs. Multiplication and division must be implemented by code
MIPS PROGRAM. ATTATION: The mult,multu,div and divu instruction cannot be used in any of your programs. Multiplication and division must be implemented by code
MIPS PROGRAM. ATTATION: The mult,multu,div and divu instruction cannot be used in any of your programs. Multiplication and division must be implemented by code
MIPS PROGRAM. ATTATION: The mult,multu,div and divu instruction cannot be used in any of your programs. Multiplication and division must be implemented by code

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site