Hello everyone,I'm new in MIPS programming, can anyone show me how to write code for these two programs.

1)Write a procedure called order that accepts two arguments. The first argument is the address of the array and the second argument is the index of an array element i. The procedure should perform the following data manipulation on the given array and return a value of 0 or 1 as appropriate:

temp1 = a[i];
temp2 = a[i + 1];
if (temp1 > temp2) 
{
a[i] = temp2;
a[i + 1] = temp1;
return 1
}
else
return 0

Devise a method to test your procedure.

2)The following procedure sort accepts two arguments; the first is the address of the integer array and the second is the number of elements in the array. The procedure sorts the integers into an order that is determined by the behaviour of procedure order upon which it makes a call.

Incorporate this procedure into your program and verify that it functions correctly together with your procedures.

sort:   
subu    $sp,$sp,44  # Stack frame is 44 bytes long
sw  $ra,20($sp) # Save return address
sw  $fp,16($sp) # Save old frame pointer
addu    $fp,$sp,36  # Set up frame pointer
sw  $s0,24($sp) # save callee-saved registers on stack...
sw  $s1,28($sp)
sw  $s2,32($sp)
sw  $s3,36($sp)
sw  $s4,40($sp)

move $s4,$a0     # Make a safe copy of array base address
addi    $s1,$a1,-1  # Loop (array_size - 1) times
sloop1: 
li  $s0,0    # Sloop2 counter / array index
move    $s2,$s4  # Copy base address of array
li  $s3,0   
sloop2:
move $a0,$s4     # First argument is base address of array
move    $a1,$s0  # Second argument is current array index
jal order    # Call the order procedure
beqz    $v0,nochng  # Any pair of elements needed swapping?
li  $s3,1    # If so, set flag for another iteration
nochng: 
addi    $s2,$s2,4    # Calculate address of next element
addi    $s0,$s0,1    # Increment sloop2 counter
blt $s0,$s1,sloop2  # Repeat if not finished iteration
bnez    $s3,sloop1  # Repeat if another iteration needed

lw  $s0,24($sp) # Restore callee-saved registers... 
lw  $s1,28($sp)
lw  $s2,32($sp)
lw  $s3,36($sp)
lw  $s4,40($sp)
lw  $ra,20($sp) # Restore return address
lw  $fp,16($sp) # Restore frame pointer
addu    $sp,$sp,44  # Pop stack frame
jr  $ra  # Return to caller

Need Help please ASAP, and your help would be much appreciated and greatful.
Thanks in Advance.

OK, can you post what you have so far?

Have no idea so for

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.