PIZZA_OPT_SIZE_STR_OFFS = 0 PIZZA_OPT_PRICE_CENTS_OFFS = PIZZA_OPT_SIZE_STR_OFFS + 10+2 PIZZA_OPT_SIZE = PIZZA_OPT_PRICE_CENTS_OFFS + 4 .text print_pizza_t: # void print_pizza_t(struct pizza_t *pizza) { #argument in $a0 is a pointer to a pizza move $t0, $a0 la $a0, size_str li $v0, 4 syscall # printf("Size: "); move $a0, $t0 addi $a0, $a0, PIZZA_OPT_SIZE_STR_OFFS li $v0, 4 syscall # printf("%s", pizza->size); la $a0, price_str li $v0, 4 syscall # printf(", price: "); lw $a0, PIZZA_OPT_PRICE_CENTS_OFFS($t0) li $v0, 1 syscall # printf("%d", pizza->price_cents); la $a0, cents_str li $v0, 4 syscall # printf(" cents\n"); jr $ra increase_price: #void increase_price(struct pizza_t *pizza, int increase_cents) #two arguments - $a0 which is the pointer # - $a1 which is the increase_cents lw $t0, PIZZA_OPT_PRICE_CENTS_OFFS($a0) #load current pizza->price # and we put it in t0 add $t0, $t0, $a1 sw $t0, PIZZA_OPT_PRICE_CENTS_OFFS($a0) #pizza->price_cents += increase_cents; jr $ra main: #int main() { begin push $ra push $s0 la $a0, welcome_str li $v0, 4 syscall #printf("The available pizza options are:\n"); #s0 is being used for int i; li $s0, 0 #int i = 0; loop__cond: bge $s0, 3, loop__end #if (i >= 3) goto loop__end; la $t1, pizza_opts #base address of pizza_opts[0] li $t2, PIZZA_OPT_SIZE #this is the size of each pizza_opt mul $t2, $s0, $t2 #multiply the size by "i" (our counter) add $t1, $t1, $t2 #add it to get &pizza_opts[i] #struct pizza_t *pizza_opt = &pizza_opts[i]; move $a0, $t1 li $a1, 100 jal increase_price #increase_price(pizza_opt, 100); move $a0, $t1 jal print_pizza_t #print_pizza_t(pizza_opt); addi $s0, $s0, 1 #i++; b loop__cond #goto loop__cond loop__end: li $v0, 0 pop $s0 pop $ra end jr $ra .data size_str: .asciiz "Size: " price_str: .asciiz ", price: " cents_str: .asciiz " cents\n" welcome_str: .asciiz "The available pizza options are:\n" .align 2 pizza_opts: .asciiz "small" #6 bytes .space 4 # + 4 = 10 .align 2 .word 300 .asciiz "medium" #7 bytes .space 3 # + 3 = 10 .align 2 .word 550 .asciiz "large" #6 bytes .space 4 # + 4 = 10 .align 2 .word 800 # struct pizza_t pizza_opts[3] = { # {"small", 300}, # {"medium", 550}, # {"large", 800} # };