Assignment #4: add to code below ALL of this
please do not answer with the same code i provided in this question. Need help with the storing of the user input then doing the sort.
need code added to accept multiple inputs from user and sort them after!!! ADD necesary code to code provided below
add the prompts for the user to input a number
add a loop for input to continue until zero is entered
sort the array
print out on the screen “Sorted Array”
print out the sorted array, one number per line. Note this will require conversion of binary integers to ASCII.
You will need to use various IO traps for this assignment.
so the output will look something like this
Enter a number <Program output>
3 <User input>
Enter a number <Program output>
2 <User input>
Enter a number <Program output>
5 <User input>
Enter a number <Program output>
0 <User input. Note: this will terminate input>
Sorted Array <Program output>
2
3
5
Thanks!
.ORIG x3000
AND R2,R2,#0
LD R3, FILE
COUNT LDR R0,R3,#0
BRz END_COUNT
ADD R3,R3,#1
ADD R2,R2,#1
BRnzp COUNT
END_COUNT ADD R4,R2,#0
BRz SORTED
OUTERLOOP ADD R4,R4,#-1
BRnz SORTED
ADD R5,R4,#0
LD R3,FILE
INNERLOOP LDR R0,R3,#0
LDR R1,R3,#1
NOT R2,R1
ADD R2,R2,#1
ADD R2,R0,R2
BRnz SWAPPED
STR R1,R3,#0
STR R0,R3,#1
SWAPPED ADD R3,R3,#1
ADD R5,R5,#-1
BRp INNERLOOP
BRnzp OUTERLOOP
SORTED HALT
FILE .FILL x7000
.END
Expert Answer
main:
addiu $sp,$sp,-256
sw $31,252($sp)
sw $fp,248($sp)
move $fp,$sp
sw $0,24($fp)
lui $2,%hi($LC0)
addiu $5,$2,%lo($LC0)
lui $2,%hi(std::cout)
addiu $4,$2,%lo(std::cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop
addiu $2,$fp,240
move $5,$2
lui $2,%hi(std::cin)
addiu $4,$2,%lo(std::cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop
lw $2,240($fp)
nop
beq $2,$0,$L14
nop
lw $3,240($fp)
lw $2,24($fp)
nop
sll $2,$2,2
addiu $4,$fp,24
addu $2,$4,$2
sw $3,16($2)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
b $L4
nop
nop
$LBB2 = .
sw $0,28($fp)
lw $3,28($fp)
lw $2,24($fp)
nop
slt $2,$3,$2
beq $2,$0,$L5
nop
$LBB3 = .
$LBB4 = .
sw $0,32($fp)
lw $3,24($fp)
lw $2,28($fp)
nop
subu $3,$3,$2
lw $2,32($fp)
nop
slt $2,$2,$3
beq $2,$0,$L6
nop
lw $2,32($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $3,16($2)
lw $2,32($fp)
nop
addiu $2,$2,1
sll $2,$2,2
addiu $4,$fp,24
addu $2,$4,$2
lw $2,16($2)
nop
slt $2,$2,$3
beq $2,$0,$L7
nop
addiu $3,$fp,40
lw $2,32($fp)
nop
sll $2,$2,2
addu $4,$3,$2
lw $2,32($fp)
nop
addiu $2,$2,1
addiu $3,$fp,40
sll $2,$2,2
addu $2,$3,$2
move $5,$2
jal void std::swap<int>(int&, int&)
nop
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
b $L8
nop
$LBE4 = .
$LBE3 = .
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
b $L9
nop
$LBE2 = .
lui $2,%hi($LC1)
addiu $5,$2,%lo($LC1)
lui $2,%hi(std::cout)
addiu $4,$2,%lo(std::cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop
$LBB5 = .
sw $0,36($fp)
lw $3,36($fp)
lw $2,24($fp)
nop
slt $2,$3,$2
beq $2,$0,$L10
nop
lw $2,36($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,16($2)
nop
move $5,$2
lui $2,%hi(std::cout)
addiu $4,$2,%lo(std::cout)
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
nop
move $3,$2
lui $2,%hi(std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&))
addiu $5,$2,%lo(std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&))
move $4,$3
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
nop
lw $2,36($fp)
nop
addiu $2,$2,1
sw $2,36($fp)
b $L11
nop
$LBE5 = .
move $2,$0
move $sp,$fp
lw $31,252($sp)
lw $fp,248($sp)
addiu $sp,$sp,256
j $31
nop
$LFB1026 = .
void std::swap<int>(int&, int&):
addiu $sp,$sp,-24
sw $fp,20($sp)
move $fp,$sp
sw $4,24($fp)
sw $5,28($fp)
lw $2,24($fp)
nop
lw $2,0($2)
nop
sw $2,8($fp)
lw $2,28($fp)
nop
lw $3,0($2)
lw $2,24($fp)
nop
sw $3,0($2)
lw $2,28($fp)
lw $3,8($fp)
nop
sw $3,0($2)
nop
move $sp,$fp
lw $fp,20($sp)
addiu $sp,$sp,24
j $31
nop
$LFB1034 = .
__static_initialization_and_destruction_0(int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
lw $3,32($fp)
li $2,1 # 0x1
bne $3,$2,$L18
nop
lw $3,36($fp)
li $2,65535 # 0xffff
bne $3,$2,$L18
nop
lui $2,%hi(std::__ioinit)
addiu $4,$2,%lo(std::__ioinit)
jal std::ios_base::Init::Init()
nop
lui $2,%hi(__dso_handle)
addiu $6,$2,%lo(__dso_handle)
lui $2,%hi(std::__ioinit)
addiu $5,$2,%lo(std::__ioinit)
lui $2,%hi(std::ios_base::Init::~Init())
addiu $4,$2,%lo(std::ios_base::Init::~Init())
jal __cxa_atexit
nop
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
$LFB1035 = .
_GLOBAL__sub_I_main:
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
li $5,65535 # 0xffff
li $4,1 # 0x1
jal __static_initialization_and_destruction_0(int, int)
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop