Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Outline
ActivationRecordinRecursion:
MergeSortActivationRecord
returnaddr
$fp
arguments
Recursivemergesortprocedure
voidsort(int A[],int B[],int n){ int A1[m], A2[m]; int n1, n2; A1[m],A2[m];int n1,n2; if(n==1)B[0]=A[0]; else{ l { n1=n/2;n2=n n1; sort(A,A1,n1); sort(A+n1,A2,n2); sort (A+n1, A2, n2); merge(A1,A2,B,n1,n2); } }
$sp
A1 A2 n1 n2 returnaddr A B n
pa aramet ters
locals s
Callingmerge
merge(A1,A2,B,n1,n2); returnaddr p q A1 A2 n1 n2 returnaddr A B n a0 a1 1 a2 t0 t1 t2 P Q R i j k
addi $a0,$sp,0 addi $ 1 $ 80 ddi $a1,$sp,80 lw $a2,176($sp) lw $t8,160($sp) l $t8 160($ ) sw $t8,8($sp) lw $t8,164($sp) l $t8 164($ ) sw $t8,4($sp) addi $ $ ddi $sp,$sp,12 12 jal merge . merge:sw $ra,0($sp)
16
31
2304
Registeraddressing
op rs rt rd func Registers 0 1
31
data
PCrelativeaddressing
op rs rt PC constant
instruction
instruction
Registerindirectaddressing
op rs rt rd func instruction Register
Difficultinmanycasestowritea compiler
To take advantage of the features provided Totakeadvantageofthefeaturesprovided byconventionalCPUs.
32