PRINT_INT = 1 PRINT_STR = 4 PRINT_CHAR = 11 PIZZA_SIZE_OFFSET = 0 PIZZA_PRICE_OFFSET = 12 PIZZA_STRUCT_SIZE = 16 #struct pizza_t { # char size[10]; //Offset 0 # //2 bytes padding # int price_cents; //Offset 12 #}; //Size 16 #int main(void) { # printf("The available pizza options are:\n"); # printf("Classic:\n"); #main_loop_init: # int i = 0; #main_loop_cond: # if (i >= 3) goto main_loop2_init; //while (i < 3) { #main_loop_body: # print_pizza_t(&pizza_options[i], 0); #main_loop_inc: # i = i + 1; # goto main_loop_cond; #main_loop2_init: # i = 0; # printf("With extra toppings:\n"); #main_loop2_cond: # if (i >= 3) goto main_loop_end; //while (i < 3) { #main_loop2_body: # print_pizza_t(&pizza_options[i], 100); #main_loop2_inc: # i = i + 1; # goto main_loop2_cond; #main_loop_end: # return 0; #} #void print_pizza_t(struct pizza_t *pizza, int increase_cents) { # printf("Size: "); # printf("%s", pizza->size); # printf(", price: "); # printf("%d",pizza->price_cents+increase_cents); # printf(" cents\n"); #} .text main: #locals #$s0, $s1 main__prologue: #TODO li $v0, PRINT_STR la $a0, menu_str # printf("The available pizza options are:\n"); syscall main_loop_init: li $s0, 0 # $s0 = i li $v0, PRINT_STR la $a0, cat_str # printf("Classic:\n"); syscall main_loop_cond: bge $s0, 3, main_loop2_init main_loop_body: #TODO # Offset: i * 16 # Address of the array # &pizza_options[i]; # print_pizza_t(&pizza_options[i], 0); # increase_cents jal print_pizza main_loop_inc: addi $s0, $s0, 1 b main_loop_cond main_loop2_init: li $s0, 0 li $v0, PRINT_STR la $a0, cat_str2 # printf("With extra toppings:\n"); syscall main_loop2_cond: bge $s0, 3, main_loop2_end main_loop2_body: mul $t0, $s0, PIZZA_STRUCT_SIZE # Offset: i * 16 la $s1, pizza_options($t0) # Address of the array # &pizza_options[i]; move $a0, $s1 # print_pizza_t(&pizza_options[i], 100); li $a1, 100 jal print_pizza main_loop2_inc: addi $s0, $s0, 1 b main_loop2_cond main_loop2_end: li $v0, 0 # return 0 main__epilogue: #TODO jr $ra ######################## print_pizza: move $t0, $a0 # address move $t1, $a1 # increase_cents li $v0, PRINT_STR # printf("Size: "); la $a0, size_str syscall li $v0, PRINT_STR # printf("small"); la $a0, ($t0) syscall li $v0, PRINT_STR # printf("price: "); la $a0, price_str syscall li $v0, PRINT_INT # printf("%d: ",); lw $t2, PIZZA_PRICE_OFFSET($t0) add $t2, $t2, $t1 #increase price move $a0, $t2 syscall li $v0, PRINT_STR # printf(" cents "); la $a0, cents_str syscall jr $ra .data menu_str: .asciiz "The available pizza options are:\n" cat_str: .asciiz "Classic:\n" cat_str2: .asciiz "With extra toppings:\n" size_str: .asciiz "Size: " price_str: .asciiz ", price: " cents_str: .asciiz " cents\n" .align 2 pizza_options: .asciiz "small" .space 10 - 6 .space 2 .word 300 .asciiz "medium" .space 10 - 7 .space 2 .word 550 .asciiz "large" .space 10 - 6 .space 2 .word 800 # {"small", 300}, # {"medium", 550}, # {"large", 800}