Question

Consider the C source code statements shown below.

   struct person  
   {
      char name[30];  
      int id;  
      int points;  
   };  

   char Fmt[] = "Name: %s  ID: %d  Points: %d\n";  
   void display_one( struct person List[], int I )  
   {  
      printf( Fmt, List[I].name, List[I].id, List[I].points );  
   }  

Complete the SPARC assembly language code segment below so that the sequence of assembly language statements is equivalent to the C statements above.

      .section ".data"
      .align   4
Fmt:   .asciz   "Name: %s  ID: %d  Points: %d\n"
      .global  display_one
      .section ".text"
      .align   4

display_one:
      save     %sp, -96, %sp
      smul     %i1, 40, %l1
      add      %i0, %l1, %l0
      set      Fmt, %o0
      mov      %l0, %o1
      ld       [%l0+32], %o2
      ld       [%l0+36], %o3
      call     printf
      nop
      ret
      restore

I was wondering what the smul %i1, 40, %l1 line is doing. I don't understand why it is multiplying by 40. If anyone could explain that would be great. Thanks.

Was it helpful?

Solution

40 is the size of struct person:

char name[30];   // 30 bytes
                 // 2 bytes padding to make the following int aligned
int id;          // 4 bytes
int points;      // 4 bytes

The parameter I is multiplied by 40 to compute the address of List[I].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top