Write a MIPS (MARS) program that asks the user what he wants the sentinel to be
enter numbers until the sentinel is entered.--do not save the entered numbers
output the sum of all the positive numbers
the sum of all the negative numbers
how many positive numbers were entered
how many negative numbers were entered
how many zeros were entered
output if the most "type" of numbers is positive, negative or zero
do not need to check for an invalid sentinel
may assume the counts for positive, negative, and zero will all be different.
check for an invalid sentinel and check for "types" being the same
use only add, addi,sub, li, la, syscall,all forms of branch, move (no functions)
be sure to comment
Sample runs:
Enter the sentinel value (may not be 0)999
Enter a Number: 1
Enter a Number: 0
Enter a Number: 0
Enter a Number: -2
Enter a Number: -2
Enter a Number: -2
Enter a Number: 999
Sum of positive numbers: 1 Sum of negative numbers: -6
There were 1 positive numbers, 3 negative numbers and 2
zeroes
there were more negative
program exiting
-- program is finished running --
Enter the sentinel value (may not be 0)999
Enter a Number: 1
Enter a Number: 0
Enter a Number: 0
Enter a Number: 0
Enter a Number: -2
Enter a Number: -2
Enter a Number: 999
Sum of positive numbers: 1 Sum of negative numbers: -4
There were 1 positive numbers, 2 negative numbers and 3
zeroes
there were more zeros
program exiting
Please give positive ratings for my effort. Thanks.
ANSWER
.LC0:
.ascii "Enter the sentinel value (may not be 0)\000"
.LC1:
.ascii "%d\000"
.LC2:
.ascii "Enter a Number: \000"
.LC3:
.ascii "\012Sum of positive numbers : %d\000"
.LC4:
.ascii " Sum of negative numbers : %d\000"
.LC5:
.ascii "\012There were %d positive numbers, %d negative numbers "
.ascii "and %d zeroes\000"
.LC6:
.ascii "\012\012There were more positive\000"
.LC7:
.ascii "\012\012There were more negative\000"
.LC8:
.ascii "\012\012There were more zeros\000"
main:
daddiu $sp,$sp,-64
sd $31,56($sp)
sd $fp,48($sp)
sd $28,40($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
sw $0,20($fp)
ld $2,%got_page(.LC0)($28)
daddiu $4,$2,%got_ofst(.LC0)
ld $2,%call16(printf)($28)
move $25,$2
nop
daddiu $2,$fp,24
move $5,$2
ld $2,%got_page(.LC1)($28)
daddiu $4,$2,%got_ofst(.LC1)
ld $2,%call16(__isoc99_scanf)($28)
move $25,$2
nop
sw $0,0($fp)
sw $0,4($fp)
sw $0,8($fp)
sw $0,12($fp)
sw $0,16($fp)
.L7:
ld $2,%got_page(.LC2)($28)
daddiu $4,$2,%got_ofst(.LC2)
ld $2,%call16(printf)($28)
move $25,$2
nop
daddiu $2,$fp,20
move $5,$2
ld $2,%got_page(.LC1)($28)
daddiu $4,$2,%got_ofst(.LC1)
ld $2,%call16(__isoc99_scanf)($28)
move $25,$2
nop
lw $2,20($fp)
lw $3,24($fp)
beq $2,$3,.L13
nop
lw $2,20($fp)
bgez $2,.L4
nop
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
lw $2,20($fp)
lw $3,16($fp)
addu $2,$3,$2
sw $2,16($fp)
b .L7
nop
.L4:
lw $2,20($fp)
blez $2,.L6
nop
lw $2,0($fp)
addiu $2,$2,1
sw $2,0($fp)
lw $2,20($fp)
lw $3,12($fp)
addu $2,$3,$2
sw $2,12($fp)
b .L7
nop
.L6:
lw $2,8($fp)
addiu $2,$2,1
sw $2,8($fp)
b .L7
nop
.L13:
nop
lw $2,12($fp)
move $5,$2
ld $2,%got_page(.LC3)($28)
daddiu $4,$2,%got_ofst(.LC3)
ld $2,%call16(printf)($28)
move $25,$2
nop
lw $2,16($fp)
move $5,$2
ld $2,%got_page(.LC4)($28)
daddiu $4,$2,%got_ofst(.LC4)
ld $2,%call16(printf)($28)
move $25,$2
nop
lw $4,8($fp)
lw $3,4($fp)
lw $2,0($fp)
move $7,$4
move $6,$3
move $5,$2
ld $2,%got_page(.LC5)($28)
daddiu $4,$2,%got_ofst(.LC5)
ld $2,%call16(printf)($28)
move $25,$2
nop
lw $3,0($fp)
lw $2,4($fp)
slt $2,$2,$3
beq $2,$0,.L8
nop
lw $3,0($fp)
lw $2,8($fp)
slt $2,$2,$3
beq $2,$0,.L8
nop
ld $2,%got_page(.LC6)($28)
daddiu $4,$2,%got_ofst(.LC6)
ld $2,%call16(printf)($28)
move $25,$2
nop
b .L9
nop
.L8:
lw $3,4($fp)
lw $2,0($fp)
slt $2,$2,$3
beq $2,$0,.L10
nop
lw $3,4($fp)
lw $2,8($fp)
slt $2,$2,$3
beq $2,$0,.L10
nop
ld $2,%got_page(.LC7)($28)
daddiu $4,$2,%got_ofst(.LC7)
ld $2,%call16(printf)($28)
move $25,$2
nop
b .L9
nop
.L10:
ld $2,%got_page(.LC8)($28)
daddiu $4,$2,%got_ofst(.LC8)
ld $2,%call16(printf)($28)
move $25,$2
nop
.L9:
move $2,$0
move $sp,$fp
ld $31,56($sp)
ld $fp,48($sp)
ld $28,40($sp)
daddiu $sp,$sp,64
j $31
nop
IMAGE OF OUTPUT
Get Answers For Free
Most questions answered within 1 hours.