6 /**************************************************************************
8 * -- function arguments that are enumerated types
9 * -- small structure arguments ( <= 64 bits )
10 * -- stored in registers
11 * -- stored on the stack
12 * -- large structure arguments ( > 64 bits )
13 * -- stored in registers
14 * -- stored on the stack
16 * -- caller is a leaf routine :
17 * -- use the call command from within an init routine (i.e.
18 * init_bit_flags, init_bit_flags_combo, init_array_rep)
19 * -- caller doesn't have enough space for all the function arguments :
20 * -- call print_long_arg_list from inside print_small_structs
21 ***************************************************************************/
23 /* Some enumerated types -- used to test that the structureal data type is
24 * retrieved for function arguments with typedef data types.
48 /* A large structure (> 64 bits) used to test passing large structures as
52 struct array_rep_info_t
{
58 /*****************************************************************************
59 * Small structures ( <= 64 bits). These are used to test passing small
60 * structures as parameters and test argument size promotion.
61 *****************************************************************************/
65 struct small_rep_info_t
{
70 /* 6 bits : really fits in 8 bits and is promoted to 32 bits
81 /* 22 bits : really fits in 40 bits and is promoted to 64 bits
83 struct bit_flags_combo_t
{
102 struct two_floats_t
{
107 /* 16 bits : promoted to 32 bits
114 /* 24 bits : promoted to 32 bits
116 struct three_char_t
{
122 /* 40 bits : promoted to 64 bits
132 /* 40 bits : promoted to 64 bits
134 struct int_char_combo_t
{
139 /*****************************************************************
140 * PRINT_STUDENT_ID_SHIRT_COLOR :
141 * IN id_int student -- enumerated type
142 * IN colors shirt -- enumerated type
143 *****************************************************************/
145 void print_student_id_shirt_color (id_int student
, colors shirt
)
147 void print_student_id_shirt_color ( student
, shirt
)
153 printf("student id : %d\t", student
);
154 printf("shirt color : ");
156 case BLACK
: printf("BLACK\n");
158 case BLUE
: printf("BLUE\n");
160 case BROWN
: printf("BROWN\n");
162 case ECRUE
: printf("ECRUE\n");
164 case GOLD
: printf("GOLD\n");
166 case GRAY
: printf("GRAY\n");
168 case GREEN
: printf("GREEN\n");
170 case IVORY
: printf("IVORY\n");
172 case MAUVE
: printf("MAUVE\n");
174 case ORANGE
: printf("ORANGE\n");
176 case PINK
: printf("PINK\n");
178 case PURPLE
: printf("PURPLE\n");
180 case RED
: printf("RED\n");
182 case SILVER
: printf("SILVER\n");
184 case TAN
: printf("TAN\n");
186 case VIOLET
: printf("VIOLET\n");
188 case WHITE
: printf("WHITE\n");
190 case YELLOW
: printf("YELLOW\n");
195 /*****************************************************************
197 * IN char array_c[] -- character array
198 *****************************************************************/
200 void print_char_array (char array_c
[])
202 void print_char_array ( array_c
)
209 printf("array_c :\n");
210 printf("=========\n\n");
211 for (index
= 0; index
< 120; index
++) {
212 printf("%1c", array_c
[index
]);
213 if ((index
%50) == 0) printf("\n");
218 /*****************************************************************
219 * PRINT_DOUBLE_ARRAY :
220 * IN double array_d[] -- array of doubles
221 *****************************************************************/
223 void print_double_array (double array_d
[])
225 void print_double_array (array_d
)
232 printf("array_d :\n");
233 printf("=========\n\n");
234 for (index
= 0; index
< 9; index
++) {
235 printf("%f ", array_d
[index
]);
236 if ((index
%8) == 0) printf("\n");
241 /*****************************************************************
243 * IN float array_f[] -- array of floats
244 *****************************************************************/
246 void print_float_array (float array_f
[])
248 void print_float_array ( array_f
)
255 printf("array_f :\n");
256 printf("=========\n\n");
257 for (index
= 0; index
< 15; index
++) {
258 printf("%f ", array_f
[index
]);
259 if ((index
%8) == 0) printf("\n");
265 /*****************************************************************
267 * IN int array_i[] -- array of integers
268 *****************************************************************/
270 void print_int_array (int array_i
[])
272 void print_int_array ( array_i
)
279 printf("array_i :\n");
280 printf("=========\n\n");
281 for (index
= 0; index
< 50; index
++) {
282 printf("%d ", array_i
[index
]);
283 if ((index
%8) == 0) printf("\n");
289 /*****************************************************************
291 * IN int array_i[] -- array of integers
292 * IN char array_c[] -- array of characters
293 * IN float array_f[] -- array of floats
294 * IN double array_d[] -- array of doubles
295 *****************************************************************/
297 void print_all_arrays(int array_i
[], char array_c
[], float array_f
[], double array_d
[])
299 void print_all_arrays( array_i
, array_c
, array_f
, array_d
)
306 print_int_array(array_i
);
307 print_char_array(array_c
);
308 print_float_array(array_f
);
309 print_double_array(array_d
);
312 /*****************************************************************
314 * A do nothing function. Used to provide a point at which calls can be made.
315 *****************************************************************/
320 for (index
=0; index
<4; index
++);
323 /*****************************************************************
324 * COMPUTE_WITH_SMALL_STRUCTS :
325 * A do nothing function. Used to provide a point at which calls can be made.
327 *****************************************************************/
329 void compute_with_small_structs (int seed
)
331 void compute_with_small_structs ( seed
)
336 struct small_rep_info_t array
[4];
339 for (index
= 0; index
< 4; index
++) {
340 array
[index
].value
= index
*seed
;
341 array
[index
].head
= (index
+1)*seed
;
344 for (index
= 1; index
< 4; index
++) {
345 array
[index
].value
= array
[index
].value
+ array
[index
-1].value
;
346 array
[index
].head
= array
[index
].head
+ array
[index
-1].head
;
350 /*****************************************************************
352 * Initializes a bit_flags_t structure. Can call this function see
353 * the call command behavior when integer arguments do not fit into
354 * registers and must be placed on the stack.
355 * OUT struct bit_flags_t *bit_flags -- structure to be filled
356 * IN unsigned a -- 0 or 1
357 * IN unsigned b -- 0 or 1
358 * IN unsigned g -- 0 or 1
359 * IN unsigned d -- 0 or 1
360 * IN unsigned e -- 0 or 1
361 * IN unsigned o -- 0 or 1
362 *****************************************************************/
364 void init_bit_flags (struct bit_flags_t
*bit_flags
, unsigned a
, unsigned b
, unsigned g
, unsigned d
, unsigned e
, unsigned o
)
366 void init_bit_flags ( bit_flags
, a
, b
, g
, d
, e
, o
)
367 struct bit_flags_t
*bit_flags
;
377 bit_flags
->alpha
= a
;
379 bit_flags
->gamma
= g
;
380 bit_flags
->delta
= d
;
381 bit_flags
->epsilon
= e
;
382 bit_flags
->omega
= o
;
385 /*****************************************************************
386 * INIT_BIT_FLAGS_COMBO :
387 * Initializes a bit_flags_combo_t structure. Can call this function
388 * to see the call command behavior when integer and character arguments
389 * do not fit into registers and must be placed on the stack.
390 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
391 * IN unsigned a -- 0 or 1
392 * IN unsigned b -- 0 or 1
394 * IN unsigned g -- 0 or 1
395 * IN unsigned d -- 0 or 1
397 * IN unsigned e -- 0 or 1
398 * IN unsigned o -- 0 or 1
399 *****************************************************************/
401 void init_bit_flags_combo (struct bit_flags_combo_t
*bit_flags_combo
, unsigned a
, unsigned b
, char ch1
, unsigned g
, unsigned d
, char ch2
, unsigned e
, unsigned o
)
403 void init_bit_flags_combo ( bit_flags_combo
, a
, b
, ch1
, g
, d
, ch2
, e
, o
)
404 struct bit_flags_combo_t
*bit_flags_combo
;
416 bit_flags_combo
->alpha
= a
;
417 bit_flags_combo
->beta
= b
;
418 bit_flags_combo
->ch1
= ch1
;
419 bit_flags_combo
->gamma
= g
;
420 bit_flags_combo
->delta
= d
;
421 bit_flags_combo
->ch2
= ch2
;
422 bit_flags_combo
->epsilon
= e
;
423 bit_flags_combo
->omega
= o
;
427 /*****************************************************************
429 * OUT struct one_double_t *one_double -- structure to fill
431 *****************************************************************/
433 void init_one_double (struct one_double_t
*one_double
, double init_val
)
435 void init_one_double ( one_double
, init_val
)
436 struct one_double_t
*one_double
;
441 one_double
->double1
= init_val
;
444 /*****************************************************************
446 * OUT struct two_floats_t *two_floats -- structure to be filled
449 *****************************************************************/
451 void init_two_floats (struct two_floats_t
*two_floats
, float init_val1
, float init_val2
)
453 void init_two_floats ( two_floats
, init_val1
, init_val2
)
454 struct two_floats_t
*two_floats
;
459 two_floats
->float1
= init_val1
;
460 two_floats
->float2
= init_val2
;
463 /*****************************************************************
465 * OUT struct two_char_t *two_char -- structure to be filled
468 *****************************************************************/
470 void init_two_chars (struct two_char_t
*two_char
, char init_val1
, char init_val2
)
472 void init_two_chars ( two_char
, init_val1
, init_val2
)
473 struct two_char_t
*two_char
;
479 two_char
->ch1
= init_val1
;
480 two_char
->ch2
= init_val2
;
483 /*****************************************************************
485 * OUT struct three_char_t *three_char -- structure to be filled
489 *****************************************************************/
491 void init_three_chars (struct three_char_t
*three_char
, char init_val1
, char init_val2
, char init_val3
)
493 void init_three_chars ( three_char
, init_val1
, init_val2
, init_val3
)
494 struct three_char_t
*three_char
;
501 three_char
->ch1
= init_val1
;
502 three_char
->ch2
= init_val2
;
503 three_char
->ch3
= init_val3
;
506 /*****************************************************************
508 * OUT struct five_char_t *five_char -- structure to be filled
514 *****************************************************************/
516 void init_five_chars (struct five_char_t
*five_char
, char init_val1
, char init_val2
, char init_val3
, char init_val4
, char init_val5
)
518 void init_five_chars ( five_char
, init_val1
, init_val2
, init_val3
,init_val4
,init_val5
)
519 struct five_char_t
*five_char
;
527 five_char
->ch1
= init_val1
;
528 five_char
->ch2
= init_val2
;
529 five_char
->ch3
= init_val3
;
530 five_char
->ch4
= init_val4
;
531 five_char
->ch5
= init_val5
;
534 /*****************************************************************
535 * INIT_INT_CHAR_COMBO :
536 * OUT struct int_char_combo_t *combo -- structure to be filled
539 *****************************************************************/
541 void init_int_char_combo (struct int_char_combo_t
*combo
, int init_val1
, char init_val2
)
543 void init_int_char_combo ( combo
, init_val1
, init_val2
)
544 struct int_char_combo_t
*combo
;
550 combo
->int1
= init_val1
;
551 combo
->ch1
= init_val2
;
554 /*****************************************************************
556 * OUT struct small_rep_into_t *small_struct -- structure to be filled
558 *****************************************************************/
560 void init_struct_rep(struct small_rep_info_t
*small_struct
, int seed
)
562 void init_struct_rep( small_struct
, seed
)
563 struct small_rep_info_t
*small_struct
;
568 small_struct
->value
= 2 + (seed
*2);
569 small_struct
->head
= 0;
572 /*****************************************************************
573 * INIT_SMALL_STRUCTS :
574 * Takes all the small structures as input and calls the appropriate
575 * initialization routine for each structure
576 *****************************************************************/
578 void init_small_structs (
579 struct small_rep_info_t
*struct1
,
580 struct small_rep_info_t
*struct2
,
581 struct small_rep_info_t
*struct3
,
582 struct small_rep_info_t
*struct4
,
583 struct bit_flags_t
*flags
,
584 struct bit_flags_combo_t
*flags_combo
,
585 struct three_char_t
*three_char
,
586 struct five_char_t
*five_char
,
587 struct int_char_combo_t
*int_char_combo
,
588 struct one_double_t
*d1
,
589 struct one_double_t
*d2
,
590 struct one_double_t
*d3
,
591 struct two_floats_t
*f1
,
592 struct two_floats_t
*f2
,
593 struct two_floats_t
*f3
)
595 void init_small_structs (struct1
, struct2
, struct3
,struct4
,flags
,flags_combo
,
596 three_char
, five_char
,int_char_combo
, d1
, d2
,d3
,f1
,f2
,f3
)
597 struct small_rep_info_t
*struct1
;
598 struct small_rep_info_t
*struct2
;
599 struct small_rep_info_t
*struct3
;
600 struct small_rep_info_t
*struct4
;
601 struct bit_flags_t
*flags
;
602 struct bit_flags_combo_t
*flags_combo
;
603 struct three_char_t
*three_char
;
604 struct five_char_t
*five_char
;
605 struct int_char_combo_t
*int_char_combo
;
606 struct one_double_t
*d1
;
607 struct one_double_t
*d2
;
608 struct one_double_t
*d3
;
609 struct two_floats_t
*f1
;
610 struct two_floats_t
*f2
;
611 struct two_floats_t
*f3
;
615 init_bit_flags(flags
, (unsigned)1, (unsigned)0, (unsigned)1,
616 (unsigned)0, (unsigned)1, (unsigned)0 );
617 init_bit_flags_combo(flags_combo
, (unsigned)1, (unsigned)0, 'y',
618 (unsigned)1, (unsigned)0, 'n',
619 (unsigned)1, (unsigned)0 );
620 init_three_chars(three_char
, 'a', 'b', 'c');
621 init_five_chars(five_char
, 'l', 'm', 'n', 'o', 'p');
622 init_int_char_combo(int_char_combo
, 123, 'z');
623 init_struct_rep(struct1
, 2);
624 init_struct_rep(struct2
, 4);
625 init_struct_rep(struct3
, 5);
626 init_struct_rep(struct4
, 6);
627 init_one_double ( d1
, 10.5);
628 init_one_double ( d2
, -3.375);
629 init_one_double ( d3
, 675.09375);
630 init_two_floats ( f1
, 45.234, 43.6);
631 init_two_floats ( f2
, 78.01, 122.10);
632 init_two_floats ( f3
, -1232.345, -199.21);
635 /*****************************************************************
636 * PRINT_TEN_DOUBLES :
637 * ?????????????????????????????
638 ****************************************************************/
640 void print_ten_doubles (
652 void print_ten_doubles ( d1
, d2
, d3
, d4
, d5
, d6
, d7
, d8
, d9
, d10
)
666 printf("Two Doubles : %f\t%f\n", d1
, d2
);
667 printf("Two Doubles : %f\t%f\n", d3
, d4
);
668 printf("Two Doubles : %f\t%f\n", d5
, d6
);
669 printf("Two Doubles : %f\t%f\n", d7
, d8
);
670 printf("Two Doubles : %f\t%f\n", d9
, d10
);
673 /*****************************************************************
675 * IN struct bit_flags_t bit_flags
676 ****************************************************************/
678 void print_bit_flags (struct bit_flags_t bit_flags
)
680 void print_bit_flags ( bit_flags
)
681 struct bit_flags_t bit_flags
;
685 if (bit_flags
.alpha
) printf("alpha\n");
686 if (bit_flags
.beta
) printf("beta\n");
687 if (bit_flags
.gamma
) printf("gamma\n");
688 if (bit_flags
.delta
) printf("delta\n");
689 if (bit_flags
.epsilon
) printf("epsilon\n");
690 if (bit_flags
.omega
) printf("omega\n");
693 /*****************************************************************
694 * PRINT_BIT_FLAGS_COMBO :
695 * IN struct bit_flags_combo_t bit_flags_combo
696 ****************************************************************/
698 void print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo
)
700 void print_bit_flags_combo ( bit_flags_combo
)
701 struct bit_flags_combo_t bit_flags_combo
;
705 if (bit_flags_combo
.alpha
) printf("alpha\n");
706 if (bit_flags_combo
.beta
) printf("beta\n");
707 if (bit_flags_combo
.gamma
) printf("gamma\n");
708 if (bit_flags_combo
.delta
) printf("delta\n");
709 if (bit_flags_combo
.epsilon
) printf("epsilon\n");
710 if (bit_flags_combo
.omega
) printf("omega\n");
711 printf("ch1: %c\tch2: %c\n", bit_flags_combo
.ch1
, bit_flags_combo
.ch2
);
714 /*****************************************************************
716 * IN struct one_double_t one_double
717 ****************************************************************/
719 void print_one_double (struct one_double_t one_double
)
721 void print_one_double ( one_double
)
722 struct one_double_t one_double
;
726 printf("Contents of one_double_t: \n\n");
727 printf("%f\n", one_double
.double1
);
730 /*****************************************************************
732 * IN struct two_floats_t two_floats
733 ****************************************************************/
735 void print_two_floats (struct two_floats_t two_floats
)
737 void print_two_floats ( two_floats
)
738 struct two_floats_t two_floats
;
742 printf("Contents of two_floats_t: \n\n");
743 printf("%f\t%f\n", two_floats
.float1
, two_floats
.float2
);
746 /*****************************************************************
748 * IN struct two_char_t two_char
749 ****************************************************************/
751 void print_two_chars (struct two_char_t two_char
)
753 void print_two_chars ( two_char
)
754 struct two_char_t two_char
;
758 printf("Contents of two_char_t: \n\n");
759 printf("%c\t%c\n", two_char
.ch1
, two_char
.ch2
);
762 /*****************************************************************
763 * PRINT_THREE_CHARS :
764 * IN struct three_char_t three_char
765 ****************************************************************/
767 void print_three_chars (struct three_char_t three_char
)
769 void print_three_chars ( three_char
)
770 struct three_char_t three_char
;
774 printf("Contents of three_char_t: \n\n");
775 printf("%c\t%c\t%c\n", three_char
.ch1
, three_char
.ch2
, three_char
.ch3
);
778 /*****************************************************************
780 * IN struct five_char_t five_char
781 ****************************************************************/
783 void print_five_chars (struct five_char_t five_char
)
785 void print_five_chars ( five_char
)
786 struct five_char_t five_char
;
790 printf("Contents of five_char_t: \n\n");
791 printf("%c\t%c\t%c\t%c\t%c\n", five_char
.ch1
, five_char
.ch2
,
792 five_char
.ch3
, five_char
.ch4
,
796 /*****************************************************************
797 * PRINT_INT_CHAR_COMBO :
798 * IN struct int_char_combo_t int_char_combo
799 ****************************************************************/
801 void print_int_char_combo (struct int_char_combo_t int_char_combo
)
803 void print_int_char_combo ( int_char_combo
)
804 struct int_char_combo_t int_char_combo
;
808 printf("Contents of int_char_combo_t: \n\n");
809 printf("%d\t%c\n", int_char_combo
.int1
, int_char_combo
.ch1
);
812 /*****************************************************************
814 * The last parameter must go onto the stack rather than into a register.
815 * This is a good function to call to test small structures.
816 * IN struct small_rep_info_t struct1
817 * IN struct small_rep_info_t struct2
818 * IN struct small_rep_info_t struct3
819 ****************************************************************/
821 void print_struct_rep(
822 struct small_rep_info_t struct1
,
823 struct small_rep_info_t struct2
,
824 struct small_rep_info_t struct3
)
826 void print_struct_rep( struct1
, struct2
, struct3
)
827 struct small_rep_info_t struct1
;
828 struct small_rep_info_t struct2
;
829 struct small_rep_info_t struct3
;
834 printf("Contents of struct1: \n\n");
835 printf("%10d%10d\n", struct1
.value
, struct1
.head
);
836 printf("Contents of struct2: \n\n");
837 printf("%10d%10d\n", struct2
.value
, struct2
.head
);
838 printf("Contents of struct3: \n\n");
839 printf("%10d%10d\n", struct3
.value
, struct3
.head
);
843 /*****************************************************************
845 * The last two parameters must go onto the stack rather than into a register.
846 * This is a good function to call to test small structures.
847 * IN struct small_rep_info_t struct1
848 * IN struct small_rep_info_t struct2
849 * IN struct small_rep_info_t struct3
850 * IN struct small_rep_info_t struct4
851 ****************************************************************/
853 void sum_struct_print (
855 struct small_rep_info_t struct1
,
856 struct small_rep_info_t struct2
,
857 struct small_rep_info_t struct3
,
858 struct small_rep_info_t struct4
)
860 void sum_struct_print ( seed
, struct1
, struct2
, struct3
, struct4
)
862 struct small_rep_info_t struct1
;
863 struct small_rep_info_t struct2
;
864 struct small_rep_info_t struct3
;
865 struct small_rep_info_t struct4
;
870 printf("Sum of the 4 struct values and seed : \n\n");
871 sum
= seed
+ struct1
.value
+ struct2
.value
+ struct3
.value
+ struct4
.value
;
872 printf("%10d\n", sum
);
875 /*****************************************************************
876 * PRINT_SMALL_STRUCTS :
877 * This is a good function to call to test small structures.
878 * All of the small structures of odd sizes (40 bits, 8bits, etc.)
879 * are pushed onto the stack.
880 ****************************************************************/
882 void print_small_structs (
883 struct small_rep_info_t struct1
,
884 struct small_rep_info_t struct2
,
885 struct small_rep_info_t struct3
,
886 struct small_rep_info_t struct4
,
887 struct bit_flags_t flags
,
888 struct bit_flags_combo_t flags_combo
,
889 struct three_char_t three_char
,
890 struct five_char_t five_char
,
891 struct int_char_combo_t int_char_combo
,
892 struct one_double_t d1
,
893 struct one_double_t d2
,
894 struct one_double_t d3
,
895 struct two_floats_t f1
,
896 struct two_floats_t f2
,
897 struct two_floats_t f3
)
899 void print_small_structs ( struct1
, struct2
, struct3
, struct4
, flags
,
900 flags_combo
, three_char
, five_char
, int_char_combo
, d1
, d2
,d3
,f1
,f2
,f3
)
901 struct small_rep_info_t struct1
;
902 struct small_rep_info_t struct2
;
903 struct small_rep_info_t struct3
;
904 struct small_rep_info_t struct4
;
905 struct bit_flags_t flags
;
906 struct bit_flags_combo_t flags_combo
;
907 struct three_char_t three_char
;
908 struct five_char_t five_char
;
909 struct int_char_combo_t int_char_combo
;
910 struct one_double_t d1
;
911 struct one_double_t d2
;
912 struct one_double_t d3
;
913 struct two_floats_t f1
;
914 struct two_floats_t f2
;
915 struct two_floats_t f3
;
918 print_bit_flags(flags
);
919 print_bit_flags_combo(flags_combo
);
920 print_three_chars(three_char
);
921 print_five_chars(five_char
);
922 print_int_char_combo(int_char_combo
);
923 sum_struct_print(10, struct1
, struct2
, struct3
, struct4
);
924 print_struct_rep(struct1
, struct2
, struct3
);
925 print_one_double(d1
);
926 print_one_double(d2
);
927 print_one_double(d3
);
928 print_two_floats(f1
);
929 print_two_floats(f2
);
930 print_two_floats(f3
);
933 /*****************************************************************
934 * PRINT_LONG_ARG_LIST :
935 * This is a good function to call to test small structures.
936 * The first two parameters ( the doubles ) go into registers. The
937 * remaining arguments are pushed onto the stack. Depending on where
938 * print_long_arg_list is called from, the size of the argument list
939 * may force more space to be pushed onto the stack as part of the callers
941 ****************************************************************/
943 void print_long_arg_list (
950 struct small_rep_info_t struct1
,
951 struct small_rep_info_t struct2
,
952 struct small_rep_info_t struct3
,
953 struct small_rep_info_t struct4
,
954 struct bit_flags_t flags
,
955 struct bit_flags_combo_t flags_combo
,
956 struct three_char_t three_char
,
957 struct five_char_t five_char
,
958 struct int_char_combo_t int_char_combo
,
959 struct one_double_t d1
,
960 struct one_double_t d2
,
961 struct one_double_t d3
,
962 struct two_floats_t f1
,
963 struct two_floats_t f2
,
964 struct two_floats_t f3
)
966 void print_long_arg_list ( a
, b
, c
, d
, e
, f
, struct1
, struct2
, struct3
,
967 struct4
, flags
, flags_combo
, three_char
, five_char
, int_char_combo
, d1
,d2
,d3
,
975 struct small_rep_info_t struct1
;
976 struct small_rep_info_t struct2
;
977 struct small_rep_info_t struct3
;
978 struct small_rep_info_t struct4
;
979 struct bit_flags_t flags
;
980 struct bit_flags_combo_t flags_combo
;
981 struct three_char_t three_char
;
982 struct five_char_t five_char
;
983 struct int_char_combo_t int_char_combo
;
984 struct one_double_t d1
;
985 struct one_double_t d2
;
986 struct one_double_t d3
;
987 struct two_floats_t f1
;
988 struct two_floats_t f2
;
989 struct two_floats_t f3
;
992 printf("double : %f\n", a
);
993 printf("double : %f\n", b
);
994 printf("int : %d\n", c
);
995 printf("int : %d\n", d
);
996 printf("int : %d\n", e
);
997 printf("int : %d\n", f
);
998 print_small_structs( struct1
, struct2
, struct3
, struct4
, flags
, flags_combo
,
999 three_char
, five_char
, int_char_combo
, d1
, d2
, d3
,
1005 void print_one_large_struct (struct array_rep_info_t linked_list1
)
1007 void print_one_large_struct( linked_list1
)
1008 struct array_rep_info_t linked_list1
;
1012 /* printf("Contents of linked list1: \n\n");
1013 printf("Element Value | Index of Next Element\n");
1014 printf("-------------------------------------\n");
1016 /*for (index = 0; index < 10; index++) {*/
1018 printf("%10d%10d\n", linked_list1
.values
[0],
1019 linked_list1
.next_index
[0]);
1023 /*****************************************************************
1025 * The three structure parameters should fit into registers.
1026 * IN struct array_rep_info_t linked_list1
1027 * IN struct array_rep_info_t linked_list2
1028 * IN struct array_rep_info_t linked_list3
1029 ****************************************************************/
1031 void print_array_rep(
1032 struct array_rep_info_t linked_list1
,
1033 struct array_rep_info_t linked_list2
,
1034 struct array_rep_info_t linked_list3
)
1036 void print_array_rep( linked_list1
, linked_list2
, linked_list3
)
1037 struct array_rep_info_t linked_list1
;
1038 struct array_rep_info_t linked_list2
;
1039 struct array_rep_info_t linked_list3
;
1045 printf("Contents of linked list1: \n\n");
1046 printf("Element Value | Index of Next Element\n");
1047 printf("-------------------------------------\n");
1049 for (index
= 0; index
< 10; index
++) {
1051 printf("%10d%10d\n", linked_list1
.values
[index
],
1052 linked_list1
.next_index
[index
]);
1055 printf("Contents of linked list2: \n\n");
1056 printf("Element Value | Index of Next Element\n");
1057 printf("-------------------------------------\n");
1059 for (index
= 0; index
< 10; index
++) {
1061 printf("%10d%10d\n", linked_list2
.values
[index
],
1062 linked_list2
.next_index
[index
]);
1065 printf("Contents of linked list3: \n\n");
1066 printf("Element Value | Index of Next Element\n");
1067 printf("-------------------------------------\n");
1069 for (index
= 0; index
< 10; index
++) {
1071 printf("%10d%10d\n", linked_list3
.values
[index
],
1072 linked_list3
.next_index
[index
]);
1077 /*****************************************************************
1079 * The last structure parameter must be pushed onto the stack
1081 * IN struct array_rep_info_t linked_list1
1082 * IN struct array_rep_info_t linked_list2
1083 * IN struct array_rep_info_t linked_list3
1084 * IN struct array_rep_info_t linked_list4
1085 ****************************************************************/
1087 void sum_array_print (
1089 struct array_rep_info_t linked_list1
,
1090 struct array_rep_info_t linked_list2
,
1091 struct array_rep_info_t linked_list3
,
1092 struct array_rep_info_t linked_list4
)
1094 void sum_array_print ( seed
, linked_list1
, linked_list2
, linked_list3
,linked_list4
)
1096 struct array_rep_info_t linked_list1
;
1097 struct array_rep_info_t linked_list2
;
1098 struct array_rep_info_t linked_list3
;
1099 struct array_rep_info_t linked_list4
;
1105 printf("Sum of 4 arrays, by element (add in seed as well): \n\n");
1106 printf("Seed: %d\n", seed
);
1107 printf("Element Index | Sum \n");
1108 printf("-------------------------\n");
1111 for (index
= 0; index
< 10; index
++) {
1113 sum
= seed
+ linked_list1
.values
[index
] + linked_list2
.values
[index
] +
1114 linked_list3
.values
[index
] + linked_list4
.values
[index
];
1115 printf("%10d%10d\n", index
, sum
);
1119 /*****************************************************************
1121 * IN struct array_rep_info_t *linked_list
1123 ****************************************************************/
1125 void init_array_rep(
1126 struct array_rep_info_t
*linked_list
,
1129 void init_array_rep( linked_list
, seed
)
1130 struct array_rep_info_t
*linked_list
;
1137 for (index
= 0; index
< 10; index
++) {
1139 linked_list
->values
[index
] = (2*index
) + (seed
*2);
1140 linked_list
->next_index
[index
] = index
+ 1;
1142 linked_list
->head
= 0;
1148 /* variables for array and enumerated type testing
1150 static char char_array
[121];
1151 static double double_array
[9];
1152 static float float_array
[15];
1153 static int integer_array
[50];
1155 static id_int student_id
= 23;
1156 static colors my_shirt
= YELLOW
;
1158 /* variables for large structure testing
1160 static int number
= 10;
1161 static struct array_rep_info_t
*list1
;
1162 static struct array_rep_info_t
*list2
;
1163 static struct array_rep_info_t
*list3
;
1164 static struct array_rep_info_t
*list4
;
1166 /* variables for testing a very long argument list
1175 /* variables for testing a small structures and a very long argument list
1177 static struct small_rep_info_t
*struct1
;
1178 static struct small_rep_info_t
*struct2
;
1179 static struct small_rep_info_t
*struct3
;
1180 static struct small_rep_info_t
*struct4
;
1181 static struct bit_flags_t
*flags
;
1182 static struct bit_flags_combo_t
*flags_combo
;
1183 static struct three_char_t
*three_char
;
1184 static struct five_char_t
*five_char
;
1185 static struct int_char_combo_t
*int_char_combo
;
1186 static struct one_double_t
*d1
;
1187 static struct one_double_t
*d2
;
1188 static struct one_double_t
*d3
;
1189 static struct two_floats_t
*f1
;
1190 static struct two_floats_t
*f2
;
1191 static struct two_floats_t
*f3
;
1193 /* Initialize arrays
1195 for (index
= 0; index
< 120; index
++) {
1196 if ((index
%2) == 0) char_array
[index
] = 'Z';
1197 else char_array
[index
] = 'a';
1199 char_array
[120] = '\0';
1201 for (index
= 0; index
< 9; index
++) {
1202 double_array
[index
] = index
*23.4567;
1205 for (index
= 0; index
< 15; index
++) {
1206 float_array
[index
] = index
/7.02;
1209 for (index
= 0; index
< 50; index
++) {
1210 integer_array
[index
] = -index
;
1215 print_char_array(char_array
);
1216 print_double_array(double_array
);
1217 print_float_array(float_array
);
1218 print_student_id_shirt_color(student_id
, my_shirt
);
1219 print_int_array(integer_array
);
1220 print_all_arrays(integer_array
, char_array
, float_array
, double_array
);
1222 /* Allocate space for large structures
1224 list1
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
1225 list2
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
1226 list3
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
1227 list4
= (struct array_rep_info_t
*)malloc(sizeof(struct array_rep_info_t
));
1229 /* Initialize large structures
1231 init_array_rep(list1
, 2);
1232 init_array_rep(list2
, 4);
1233 init_array_rep(list3
, 5);
1234 init_array_rep(list4
, 10);
1235 printf("HELLO WORLD\n");
1236 printf("BYE BYE FOR NOW\n");
1237 printf("VERY GREEN GRASS\n");
1239 /* Print large structures
1241 sum_array_print(10, *list1
, *list2
, *list3
, *list4
);
1242 print_array_rep(*list1
, *list2
, *list3
);
1243 print_one_large_struct(*list1
);
1245 /* Allocate space for small structures
1247 struct1
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
1248 struct2
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
1249 struct3
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
1250 struct4
= (struct small_rep_info_t
*)malloc(sizeof(struct small_rep_info_t
));
1251 flags
= (struct bit_flags_t
*)malloc(sizeof(struct bit_flags_t
));
1252 flags_combo
= (struct bit_flags_combo_t
*)malloc(sizeof(struct bit_flags_combo_t
));
1253 three_char
= (struct three_char_t
*)malloc(sizeof(struct three_char_t
));
1254 five_char
= (struct five_char_t
*)malloc(sizeof(struct five_char_t
));
1255 int_char_combo
= (struct int_char_combo_t
*)malloc(sizeof(struct int_char_combo_t
));
1257 d1
= (struct one_double_t
*)malloc(sizeof(struct one_double_t
));
1258 d2
= (struct one_double_t
*)malloc(sizeof(struct one_double_t
));
1259 d3
= (struct one_double_t
*)malloc(sizeof(struct one_double_t
));
1261 f1
= (struct two_floats_t
*)malloc(sizeof(struct two_floats_t
));
1262 f2
= (struct two_floats_t
*)malloc(sizeof(struct two_floats_t
));
1263 f3
= (struct two_floats_t
*)malloc(sizeof(struct two_floats_t
));
1265 /* Initialize small structures
1267 init_small_structs ( struct1
, struct2
, struct3
, struct4
, flags
,
1268 flags_combo
, three_char
, five_char
, int_char_combo
,
1269 d1
, d2
, d3
, f1
, f2
, f3
);
1271 /* Print small structures
1273 print_small_structs ( *struct1
, *struct2
, *struct3
, *struct4
, *flags
,
1274 *flags_combo
, *three_char
, *five_char
, *int_char_combo
,
1275 *d1
, *d2
, *d3
, *f1
, *f2
, *f3
);
1277 /* Print a very long arg list
1286 print_long_arg_list ( a
, b
, c
, d
, e
, f
, *struct1
, *struct2
, *struct3
, *struct4
,
1287 *flags
, *flags_combo
, *three_char
, *five_char
, *int_char_combo
,
1288 *d1
, *d2
, *d3
, *f1
, *f2
, *f3
);
1290 /* Initialize small structures
1292 init_one_double ( d1
, 1.11111);
1293 init_one_double ( d2
, -345.34);
1294 init_one_double ( d3
, 546464.2);
1295 init_two_floats ( f1
, 0.234, 453.1);
1296 init_two_floats ( f2
, 78.345, 23.09);
1297 init_two_floats ( f3
, -2.345, 1.0);
1298 init_bit_flags(flags
, (unsigned)1, (unsigned)0, (unsigned)1,
1299 (unsigned)0, (unsigned)1, (unsigned)0 );
1300 init_bit_flags_combo(flags_combo
, (unsigned)1, (unsigned)0, 'y',
1301 (unsigned)1, (unsigned)0, 'n',
1302 (unsigned)1, (unsigned)0 );
1303 init_three_chars(three_char
, 'x', 'y', 'z');
1304 init_five_chars(five_char
, 'h', 'e', 'l', 'l', 'o');
1305 init_int_char_combo(int_char_combo
, 13, '!');
1306 init_struct_rep(struct1
, 10);
1307 init_struct_rep(struct2
, 20);
1308 init_struct_rep(struct3
, 30);
1309 init_struct_rep(struct4
, 40);
1311 compute_with_small_structs(35);
1313 printf("HELLO WORLD\n");
1314 printf("BYE BYE FOR NOW\n");
1315 printf("VERY GREEN GRASS\n");
1317 /* Print small structures
1319 print_one_double(*d1
);
1320 print_one_double(*d2
);
1321 print_one_double(*d3
);
1322 print_two_floats(*f1
);
1323 print_two_floats(*f2
);
1324 print_two_floats(*f3
);
1325 print_bit_flags(*flags
);
1326 print_bit_flags_combo(*flags_combo
);
1327 print_three_chars(*three_char
);
1328 print_five_chars(*five_char
);
1329 print_int_char_combo(*int_char_combo
);
1330 sum_struct_print(10, *struct1
, *struct2
, *struct3
, *struct4
);
1331 print_struct_rep(*struct1
, *struct2
, *struct3
);