whatisit_solution

whatisit_solution - QuickSort in MIPS assembly: Converting...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
QuickSort in MIPS assembly: Converting to C Here is a normal procedure to do the conversion: 1. Figure out overall structure of the program 2. Create a function hierarchy with arguments and return values 3. Figure out loops and conditions 4. Build an execution flow for each function 5. Handle details along with assigning variables 6. Fill out the execution flow 7. Make things fancy if you want .data 0x10010000 Alength: .word 8 Aarray: .word 33, 24, 8, 28, 94, 12, 10, 53 # let’s use A[] and L for the array and its length .text main: L400000: lui $8, 4097 # address of L in $8(t0) L400004: ori $4, $8, 4 # address of A[] in $4(a0) L400008: lw $5, 0($8) # load L into $5(a1) L40000c: jal L400108 # call with args $a0, $a1 L400010: lui $8, 4097 # address of L in $8(t0) L400014: ori $4, $8, 4 # address of A[] in $4(a0) L400018: lw $8, 0($8) # load L into $8(t0) L40001c: addi $6, $8, -1 # $6(a2) = L-1 L400020: ori $5, $0, 0 # $5(a1) = 0 L400024: jal L400040 # call with args $a0, $a1, $a2 L400028: lui $8, 4097 # address of L in $8(t0) L40002c: ori $4, $8, 4 # address of A[] in $4(a0) L400030: lw $5, 0($8) # load L into $5(a1) L400034: jal L400108 # call with args $a0, $a1 L400038: ori $2, $0, 10 # L40003c: syscall # exit void main(void) //whatisit(void) { int L = 8; int A[8]={33, 24, 8, 28, 94, 12, 10, 53}; func1( &A[0], L ); // jal L400108 func2( &A[0], 0, L-1 ); // jal L400040 func1( &A[0], L ); // jal L400108 }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
func2: L400040: slt $8, $5, $6 # $5(a1), $6(a2) L400044: beq $8, $0, L400094 # if $a1>=$a2 then branch to end
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

whatisit_solution - QuickSort in MIPS assembly: Converting...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online