# struct details { # uint16_t postcode; # uint8_t wam; # uint32_t zid; # }; # offset in bytes of fields of struct details OFFSET_POSTCODE = 0 OFFSET_WAM = 2 OFFSET_ZID = 3 main: ### Save values into struct ### la $t0, student # student.postcode = 2052; addi $t1, $t0, OFFSET_POSTCODE li $t2, 2052 sh $t2, 0($t1) la $t0, student # student.wam = 95; addi $t1, $t0, OFFSET_WAM li $t2, 95 sb $t2, 0($t1) la $t0, student # student.zid = 5123456 addi $t1, $t0, OFFSET_ZID li $t2, 5123456 sw $t2, 0($t1) ### Load values from struct ### la $t0, student # printf("%d", student.zid); add $t1, $t0, OFFSET_ZID lw $a0, 0($t1) li $v0, 1 syscall li $a0, ' ' # putchar(' '); li $v0, 11 syscall la $t0, student # printf("%d", student.wam); addi $a0, $t0, OFFSET_WAM li $v0, 1 syscall li $a0, ' ' # putchar(' '); li $v0, 11 syscall la $t0, student # printf("%d", student.postcode); addi $t1, $t0, OFFSET_POSTCODE lhu $a0, 0($t1) li $v0, 1 syscall li $a0, '\n' # putchar('\n'); li $v0, 11 syscall li $v0, 0 # return 0 jr $ra .data student: # struct details student; .space 7