MIPS Programming Arrays Writing Procedures: Calling Convention

Embed Size (px)

Text of MIPS Programming Arrays Writing Procedures: Calling Convention

  • Slide 1
  • MIPS Programming Arrays Writing Procedures: Calling Convention
  • Slide 2
  • Memory Setup in C/Java C++: int *intarray = new int[10]; Java: int[] intarray = new int[10]; What does this do? What does the memory look like? Where is intarray[5] located? intarray + 20 Where is intarray[i] located? intarray + 4*i intarray intarray + 20 &(intarray[0]) + 20 intarray &(intarray[0])
  • Slide 3
  • Declaring & Initializing Global Arrays in HLL int GlobalA = 3; int GlobalB[] = {0x20040002, 0x20080001, 0x200b0001, 0x8b502a, 0x15400003, 0x01084020, 0x20840000, 0x800fffa, 0x10010200, 0x00000000}; int main(int argc, char *argv[]) { } public class MyClass{ public static int GlobalA = 3; public static int GlobalB[] = {0x20040002, 0x20080001, 0x200b0001, 0x8b502a, 0x15400003, 0x01084020, 0x20840000, 0x800fffa, 0x10010200, 0x00000000}; }; 0) { sum += N; N--; } return sum; } SumToN: add $v0, $0, $0 loop: slt $t0, $0, $a0 beq $t">
  • Another Example: int SumToN(int N) { int sum = 0; while (N > 0) { sum += N; N--; } return sum; } SumToN: add $v0, $0, $0 loop: slt $t0, $0, $a0 beq $t0, $0, end add $v0, $v0, $a0 addi $a0, $a0, -1 j loop end: jr $ra
  • Slide 23
  • Third Example: int SumNtotheM(int N, int M) { int sum = 0; while (N > 0) { sum += power(N,M); N--; } return sum; } SumToNtotheM: add $sp, $sp, -32 sw $ra, 14($sp) add $t0, $0, $0 loop:slt $t0, $0, $a0 beq $t0, $0, end sw $a0, 28($sp) sw $a1, 24($sp) sw $t0, 0($sp) jal power lw $t0, 0($sp) lw $a0, 28($sp) lw $a1, 24($sp) add $t0, $v0, $t0 addi $a0, $a0, -1 j loop end:add $v0, $t0, $0 lw $ra, 14($sp) add $sp, $sp, 32 jr $ra