/* struct_math.c Written by Tanya Amert for Fall 2024. Demonstrates working with structs in C, but is meant to be viewed in assembly. Either compile it yourself or copy the code into Compiler Explorer. To generate assembly for this program: gcc -Wall -Werror -Og -S -o struct_math.s struct_math.c To compile this program: gcc -o struct_math struct_math.s To run this program: ./struct_math */ #include typedef struct { int a; int b; int *p; char s[8]; short v[4]; } data_t; char * func0(data_t *data, unsigned int i) { return &(data->s[i]); } short func1(data_t *data, unsigned int i) { int num = data->b; short s = data->v[i]; return s ^ num; } void func2(int *x, int *y, data_t *data) { data->a = *x; data->b = *y; data->p = x; data->s[0] = 'h'; data->s[1] = 'o'; data->s[2] = 'b'; data->s[3] = 'b'; data->s[4] = 'e'; data->s[5] = 's'; data->s[6] = '\0'; data->s[7] = '\0'; data->v[0] = data->v[1] = data->v[2] = data->v[3] = 314; } char func3(data_t *data) { char total = 0; for (unsigned int i = 0; i < 8; i++) { total += data->s[i]; } return total; } short func4(data_t *data) { short prod = 1; for (unsigned int i = 0; i < 4; i++) { prod *= data->v[i]; } return prod; } int main() { data_t d; int x = 3; int y = 10; func0(&d, 3); func1(&d, 1); func2(&x, &y, &d); func3(&d); func4(&d); }