Need help faithfully translating the below Python code (ignoring type hints) into a properly commented MIPS program. Included is an example run of the expected output of the program as well as a MIPS sheet of allowed instructions that can be used. Thank you in advance for your help :)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need help faithfully translating the below Python code (ignoring type hints) into a properly commented MIPS program. Included is an example run of the expected output of the program as well as a MIPS sheet of allowed instructions that can be used. Thank you in advance for your help :)

 

Call code Service
($v0)
1
4
5
=
8
9
10
Print integer
Print string
Input integer
Input string
On function call:
Instruction format
add Rdest, Rarel, Hare2
sub Rdest, Rarel, Rare2
mult Rsrel, Rare2
div Rarel, Rsrc2
j label
jal label
and Rdest, Rsrel, Rsre2
or Rdest, Rsrel, Rare2
xor Rdest, Rarel, Rare2
nor Rdest, Rarel, Rsre2
sllv Rdest, Rarel, Rare2
srlv Rdest, Rarel, Rare2
srav Rdest, Rarel, Rarc2
jr Rare
jair Rare
syscall
Arguments
Allocate memory $a0= number of bytes
Exit
mfhi Rdest
mflo Rdest
w Rdest, Addr
sw Rsre, Addr
la Rdest, Addr(or label)**
beq Rarel, Rare2, label
bne Rarel, Rare2, label
slt Rdest, Rarel. Rsre2
$a0 value to print
$a0-address of string to print
$20 address at which the
string will be stored
R29
R30
R31
$a1 = maximum number of
characters in the string
Table 1: System calls.
R24, R25
R28
Number
Purpose
ROO
provides constant zero
R01
reserved for assembler
R02, R03
system call code, return value
R04-R07 $20--$23
system call and function arguments
R08-R15 $t0--$17 temporary storage (caller-saved)
R16-R23 $20-$s7
Sat
$v0, $v1
Table 2: General-purpose registers
Name
$zero
$18, $19
$KP
$sp
$fp
$ra
Caller:
sets $v0 to return value
clears local variables off stack
On function return: restores saved $fp off stack
restores saved $ra off stack
returns to caller with jr $ra
Subtract
Multiply
Divide
Table 3: Assembler directives
data
assemble into data segment
text
assemble into text (code) segment
word wl, w2, ...] allocate word(s) with initial value(s)
space n
ascii "string"
asciiz "string"
Returns
$v0 = entered integer
Caller:
saves temporary registers on stack
passes arguments on stack
calls function using jal falabel
$v0 address of first byte
temporary storage (callee-saved)
temporary storage (caller-saved)
pointer to global area.
Table 5: A partial instruction set is provided below. The following conventions apply.
Instruction Format column
Rare, Rarel, Rsre2: register source operand(s) - must be the name of a register
Rdest: register destination must be the name of a register
Addr: address in the form offset (Rarc), that is, absolute address Rarc offset
label: label of an instruction.
**: pseudoinstruction
stack pointer
frame pointer
return address
allocate n bytes of uninitialized, unaligned space.
allocate ASCII string, do not terminate
allocate ASCII string, terminate with "\0*
Table 4: Function calling convention
Callee:
saves value of $ra on stack
saves value of $fp on stack
Immediate Form column
Associated instruction where Rsre2 is an immediate. Symbol - appears if there is no immediate form.
Unsigned or overflow column
Associated unsigned (or overflow) instruction for the values of Rsrel and Rsre2. Symbol - if no such form.
Bitwise AND
Bitwise OR
Bitwise XOR
Bitwise NOR
Shift Left Logical
Shift Right Logical
Shift Right Arithmet
Move from Hi
Move from Lo
Load word
Store word
Load Address (for
printing strings)
Branch if equal
Branch if not equal
Set if less than
Jump
Jump and link
copies $sp to $fp
allocates local variables on stack
Table 6: Allowed MIPS instruction (and pseudoinstruction) set
Meaning
Operation
Add
Caller:
clears arguments off stack
restores temporary registers off stack
uses return value in $v0
Rdest = Rsrel + Rsrc2
Rdest=Rsrel- Rare2
Hi:Lo Rarel Rare2
Lo Rarel/Rsrc2;
Hi Rsrel % Rsrc2
Rdest Rsrel & Rsrc2
Rdest Rarel | Rsrc2
Rdest Rarel A Rare2
Rdest(Rarel | Rare2)
Rdest = Rsrel << Rsre2
Rdest = Rsrel >> Rsrc2
(MSB-0)
Rdest Rarel >> Rare2
(MSB preserved)
Rdest = Hi
Rdest Lo
Rdest meen32 Addr
mem32[Addr] Rare
Rdest=Addr
Rdest=label)
if (Rarel Rsrc2)
PC = label
if (Rarel ! Rare2)
PC label
(or
if (Rarel< Rare2)
Rdest 1
else Rdest 0
PC label
Sra PC + 4;
PC label
Jump register
PC- Rare
Jump and link register Sra = PC + 4
PC Rare
system call
depends on the value of
$VO
Immediate
addi
-
andi
ori
Notes
value is signed
string must be termi-
nated with 0
value is signed
returns if $a1-1 char
acters or Enter typed,
the string is termi-
nated with 10
ends simulation
xori
sll
srl
sra
-
slti
Unsigned or Overflow
addu (no overflow trap)
subu (no overflow trap)
divu
.
situ, sitiu
Transcribed Image Text:Call code Service ($v0) 1 4 5 = 8 9 10 Print integer Print string Input integer Input string On function call: Instruction format add Rdest, Rarel, Hare2 sub Rdest, Rarel, Rare2 mult Rsrel, Rare2 div Rarel, Rsrc2 j label jal label and Rdest, Rsrel, Rsre2 or Rdest, Rsrel, Rare2 xor Rdest, Rarel, Rare2 nor Rdest, Rarel, Rsre2 sllv Rdest, Rarel, Rare2 srlv Rdest, Rarel, Rare2 srav Rdest, Rarel, Rarc2 jr Rare jair Rare syscall Arguments Allocate memory $a0= number of bytes Exit mfhi Rdest mflo Rdest w Rdest, Addr sw Rsre, Addr la Rdest, Addr(or label)** beq Rarel, Rare2, label bne Rarel, Rare2, label slt Rdest, Rarel. Rsre2 $a0 value to print $a0-address of string to print $20 address at which the string will be stored R29 R30 R31 $a1 = maximum number of characters in the string Table 1: System calls. R24, R25 R28 Number Purpose ROO provides constant zero R01 reserved for assembler R02, R03 system call code, return value R04-R07 $20--$23 system call and function arguments R08-R15 $t0--$17 temporary storage (caller-saved) R16-R23 $20-$s7 Sat $v0, $v1 Table 2: General-purpose registers Name $zero $18, $19 $KP $sp $fp $ra Caller: sets $v0 to return value clears local variables off stack On function return: restores saved $fp off stack restores saved $ra off stack returns to caller with jr $ra Subtract Multiply Divide Table 3: Assembler directives data assemble into data segment text assemble into text (code) segment word wl, w2, ...] allocate word(s) with initial value(s) space n ascii "string" asciiz "string" Returns $v0 = entered integer Caller: saves temporary registers on stack passes arguments on stack calls function using jal falabel $v0 address of first byte temporary storage (callee-saved) temporary storage (caller-saved) pointer to global area. Table 5: A partial instruction set is provided below. The following conventions apply. Instruction Format column Rare, Rarel, Rsre2: register source operand(s) - must be the name of a register Rdest: register destination must be the name of a register Addr: address in the form offset (Rarc), that is, absolute address Rarc offset label: label of an instruction. **: pseudoinstruction stack pointer frame pointer return address allocate n bytes of uninitialized, unaligned space. allocate ASCII string, do not terminate allocate ASCII string, terminate with "\0* Table 4: Function calling convention Callee: saves value of $ra on stack saves value of $fp on stack Immediate Form column Associated instruction where Rsre2 is an immediate. Symbol - appears if there is no immediate form. Unsigned or overflow column Associated unsigned (or overflow) instruction for the values of Rsrel and Rsre2. Symbol - if no such form. Bitwise AND Bitwise OR Bitwise XOR Bitwise NOR Shift Left Logical Shift Right Logical Shift Right Arithmet Move from Hi Move from Lo Load word Store word Load Address (for printing strings) Branch if equal Branch if not equal Set if less than Jump Jump and link copies $sp to $fp allocates local variables on stack Table 6: Allowed MIPS instruction (and pseudoinstruction) set Meaning Operation Add Caller: clears arguments off stack restores temporary registers off stack uses return value in $v0 Rdest = Rsrel + Rsrc2 Rdest=Rsrel- Rare2 Hi:Lo Rarel Rare2 Lo Rarel/Rsrc2; Hi Rsrel % Rsrc2 Rdest Rsrel & Rsrc2 Rdest Rarel | Rsrc2 Rdest Rarel A Rare2 Rdest(Rarel | Rare2) Rdest = Rsrel << Rsre2 Rdest = Rsrel >> Rsrc2 (MSB-0) Rdest Rarel >> Rare2 (MSB preserved) Rdest = Hi Rdest Lo Rdest meen32 Addr mem32[Addr] Rare Rdest=Addr Rdest=label) if (Rarel Rsrc2) PC = label if (Rarel ! Rare2) PC label (or if (Rarel< Rare2) Rdest 1 else Rdest 0 PC label Sra PC + 4; PC label Jump register PC- Rare Jump and link register Sra = PC + 4 PC Rare system call depends on the value of $VO Immediate addi - andi ori Notes value is signed string must be termi- nated with 0 value is signed returns if $a1-1 char acters or Enter typed, the string is termi- nated with 10 ends simulation xori sll srl sra - slti Unsigned or Overflow addu (no overflow trap) subu (no overflow trap) divu . situ, sitiu
from typing import List, TypeVar
# DO NOT add comments to this file
# Use the provided file on the right ->
T = TypeVar('T')
def insertion_sort (the_list: List[T]):
length len(the_list)
for i in range (1, length):
key = the_list[i]
j = i-1
while j >= 0 and key <the_list[j] :
the list[j+1]
j -= 1
the_list[j]
the_list[j+1] = key
def main() -> None:
arr = [6, -2, 7, 4, -10]
insertion_sort (arr)
for i in range (len (arr)):
print (arr[i], end=" ")
print ()
main()
An example of a run is:
java -jar Mars4_5.jar task4.asn
MARS 4.5 Copyright 2003-2814 Pete Sanderson and Kenneth Vollmar
-18 -2 4 6 7
=
Transcribed Image Text:from typing import List, TypeVar # DO NOT add comments to this file # Use the provided file on the right -> T = TypeVar('T') def insertion_sort (the_list: List[T]): length len(the_list) for i in range (1, length): key = the_list[i] j = i-1 while j >= 0 and key <the_list[j] : the list[j+1] j -= 1 the_list[j] the_list[j+1] = key def main() -> None: arr = [6, -2, 7, 4, -10] insertion_sort (arr) for i in range (len (arr)): print (arr[i], end=" ") print () main() An example of a run is: java -jar Mars4_5.jar task4.asn MARS 4.5 Copyright 2003-2814 Pete Sanderson and Kenneth Vollmar -18 -2 4 6 7 =
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Processes of 3D Graphics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education