Page 170 - ARM 64 Bit Assembly Language
P. 170

Abstract data types  157


                      Listing 6.2 Definition of the image structure is hidden in a separate header file, and not
                                           available to client code that uses the ADT.

                    1  #ifndef IMAGE_PRIVATE_H
                    2  #define IMAGE_PRIVATE_H
                    3  #include <image.h>
                    4
                    5  typedef struct {
                    6   pval r,g,b;
                    7  } Pixel;
                    8
                    9  struct imageStruct {
                   10   int rows;     // number of rows in the image
                   11   int cols;     // number of columns in the image
                   12   Pixel *pixels; // array of pixel data
                   13  };
                   14  #endif




                                         Listing 6.3 Definition of an ADT in Assembly.

                    1  ### Definitions for pixel and image data structures
                    2
                    3        ## pixel
                    4         .equ   p_red,   #0  // offset to red value
                    5         .equ   p_green, #1  // offset to green value
                    6         .equ   p_blue,  #2  // offset to blue value
                    7         .equ   p_size,  #3  // size of the pixel data structure
                    8
                    9         ## image
                   10         .equ   i_rows,  #0  // offset to number of rows
                   11         .equ   i_cols,  #4  // offset to number of columns
                   12         .equ   i_pixels,#8  // offset to pointer to image data
                   13         .equ   i_size, #12  // size of the image data structure



                     Listing 6.2 shows the private implementation of the Image data type, which is included by
                     the C files which implement the Image abstract data type. A pixel is defined as a C struct
                     with one byte each for the red, blue, and green color components. Since the largest item in
                     the struct is a byte, the C compiler will create a structure that is exactly three bytes long, with-
                     out any extra bytes for alignment. The image struct contains three integer values, so it will
                     occupy twelve bytes. Listing 6.3 shows how the data structures from the previous listings can
                     be defined in assembly language. With those definitions, any of the functions declared in List-
                     ing 6.1 can be written in assembly language.
   165   166   167   168   169   170   171   172   173   174   175