


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Computer System Architecture; Subject: Computer Science; University: California State University - Fullerton; Term: Unknown 1989;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Supporting Procedure in Computer Hardware:
When calling a procedure the program must:
Which of these are done by the caller? Which of them are done by the callee?
Special registers for procedure calling:
i) Using more registers โ stack Special register $sp for stack pointer.
Example: int leaf( int g, int h, int i, int j ) { int f; f = (g + h) โ (i + j); return f; }
in MIPS:
leaf: addi $sp, $sp, - sw $t1, 8($sp) sw $t0, 4($sp) sw $s0, 0($sp) add $t0, $a0, $a add $t1, $a2, $a sub $s0, $t0, $t add $v0, $s0, $zero lw $s0, 0($sp) lw $t0, 4($sp) lw $t1, 8($sp) addi $sp, $sp, 12 jr $ra
Want to save some time from storing and recovering registers? Temporary and saved register convention:
ii) Nested Procedures โ preserve return address and parameters
Example: n! = 1 if (n=0), n! = n x (n-1)! if (n>0).
in C: int fact (int n) { if (n == 0) return (1); else return (n*fact(n-1)); }
in MIPS:
fact: addi $sp, $sp, - sw $ra, 4($sp) sw $a0, 0($sp) slti $t0, $a0, 1 beg $t0, $zero, L addi $v0, $zero, 1 addi $sp, $sp, 8 jr $ra L1: addi $a0, $a0, - jal fact lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 mul $v0, $a0, $v jr $ra
Preserved No Preserved Saved registers: $s0 - $s7 Temporary registers: $t0 - $t Stack pointer: $sp Everything in the Stack
Argument registers: $a0 - $a
Return address: $ra Return value registers: $v0, $v
iii) Allocating Space for New Data โ the frame pointer $fp and the global pointer $gp
$fp
$sp
Beyond Numbers โ processing strings:
lb $t0, 0($sp)
Arrays vs. Pointers:
Example: Clear1 (int array[], int size) { int i; for (i = 0; i<size; i++) array[i] = 0; }
in MIPS:
move $t0, $zero Loop1: sll $t1, $t0, 2 add $t2, $a0, $t sw $zero, 0($t2) addi $t0, $t0, 1 slt $t3, $t0, $a bne $t3, $zero, Loop
Another example:
Clear2 (int *array, int size) { int *p; for (p = &(array[0]); p<&(array[size]); p=p+1) *p = 0; }
in MIPS:
move $t0, $a Loop2: sw $zero, 0($t0) addi $t0, $t0, 4 sll $t1, $a1, 2 add $t2, $a0, $t slt $t3, $t0, $t bne $t3, $zero, Loop
An improved version:
move $t0, $a sll $t1, $a1, 2 add $t2, $a0, $t Loop2: sw $zero, 0($t0) addi $t0, $t0, 4 slt $t3, $t0, $t bne $t3, $zero, Loop
Notice the different between the two versions.