


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Label Instruction Comment sub $2, $1, $3 # subtract array base
slti $2, $2, 128 # is pixel in first row?
bne $2, $0, Target # then skip to target
Label Instruction Comment sub $2, $1, $3 # subtract array base
addi $2, $2, 4 # compute next pixel position
andi $2, $2, 127 # is next pixel on left edge?
beq $2, $0, Target # then skip to target
Label Instruction Comment sll $13, $13, 8 # shift red left one byte
or $13, $13, $14 # combine red and green
sll $13, $13, 8 # shift red & green left one byte
or $13, $13, $15 # add blue to red & green
sw $13, Edges($2) # store packed word in to memory
int A; int B[] = {1, 2}; char C = ‘z’; char D[] = “Hello”; int *E; char *F;
struct State { int Num; char Name[NAMELENGTH]; int YearPop[NUMYEARS]; float Growth; };
Store initial year population in integer P (^) P = S->YearPop[0];
Store first character of Name in character C C = S->Name[0];
Set Growth to percentage growth between years 0 and 1. (Don’t worry if it’s the max.)
S->Growth = 100.0 * (S->YearPop[1] – S->YearPop[0]) / S->YearPop[0];
int Bar() {
int A = 21, B = 33; char C[] = “Hi!”; int Foo(int *, char *);
Bar’s FP 9900 Bar’s RV 9896 A = 21 9892 B = 33 9888 C = “Hi!”
(^9884) Bar’s RA, 2004
(^9880) Bar’s FP, 9900
(^9876) &A, 9896
(^9872) C, 9888
label instruction comment
addi $29, $29, -20 # allocate stack space for Foo call
sw $31, 16($29) # preserve Bar’s return address
sw $30, 12($29) # preserve Bar’s frame pointer
addi $2, $30, -4 # compute address of A
sw $2, 8($29) # store &A
addi $2, $30, -12 # compute address of C[]
sw $2, 4($29) # store C
jal Foo # call Foo
lw $31, 16($29) # restore Bar’s return address
lw $30, 12($29) # restore Bar’s frame pointer
lw $2, 0($29) # load Foo’s return value
sw $2, -8($30) # store in B
addi $29, $29, 20 # deallocate stack space for Foo call