C C This program shows aligned and unaligned data in a COMMON block: C C COMMON_ORDER_NUMBER (aligned longword) C COMMON_ITEM_NUMBER (unaligned word) C C and aligned and unaligned data in a RECORD statement: C C ORDER_NUMBER (aligned longword) C ITEM_NUMBER (unaligned word) C PROGRAM EXAMPLE INTEGER*4 COMMON_ORDER_NUMBER CHARACTER*9 COMMON_ZIP_CODE INTEGER*2 COMMON_ITEM_NUMBER COMMON COMMON_ORDER_NUMBER,COMMON_ZIP_CODE COMMON COMMON_ITEM_NUMBER STRUCTURE /FILE_REC_STRUCT/ INTEGER*4 ORDER_NUMBER CHARACTER*9 ZIP_CODE INTEGER*2 ITEM_NUMBER END STRUCTURE RECORD /FILE_REC_STRUCT/ DATA1 DATA1.ORDER_NUMBER = 256 DATA1.ITEM_NUMBER = 365 STOP END ------------------------------------------------------------------------------- Listing File: Showing alignment warning messages 1 PROGRAM EXAMPLE 2 3 INTEGER*4 COMMON_ORDER_NUMBER 4 CHARACTER*9 COMMON_ZIP_CODE 5 INTEGER*2 COMMON_ITEM_NUMBER ..................1 %FORT-W-MISALIGN, (1) Alignment of variable or array is inconsistent with its data type 6 7 COMMON COMMON_ORDER_NUMBER,COMMON_ZIP_CODE 8 COMMON COMMON_ITEM_NUMBER 9 10 STRUCTURE /FILE_REC_STRUCT/ 11 INTEGER*4 ORDER_NUMBER 12 CHARACTER*9 ZIP_CODE 13 INTEGER*2 ITEM_NUMBER 14 END STRUCTURE 15 16 RECORD /FILE_REC_STRUCT/ DATA1 .................................1 %FORT-W-FLDMISALN, (1) Record contains one or more misaligned fields 17 18 DATA1.ORDER_NUMBER = 256 19 DATA1.ITEM_NUMBER = 365 20 STOP 21 END Generated code for aligned and unaligned data references: Fortran line Aligned Machine Code Unaligned Machine Code ------------------------------------------------------------------------------- R0 <-- base addr of structure DATA1.ORDER_NUMBER = 256 MOV 256, R19 MOV 256, R21 STL R19, (R0) STL R21, (R0) DATA1.ITEM_NUMBER = 365 LDQ R0, 48(R27) MOV 365, R1 MOV 365, R1 LDA R16, 13(R0) LDA R16, 14(R0) BIC R16, 3, R17 INSWL R1, R16, R18 AND R16, 3, R20 LDQ_U R17, 14(R0) LDL R18, (R17) INSWL R1, R20, R19 MSKWL R18, R20, R18 BIS R18, R19, R18 CMPULE R20, 2, R19 STL R18, (R17) BEQ R19, L$2 L$1: : : L$2: : LDL R18, 4(R17) EXTBL R1, 1, R19 BIC R18, 255, R18 BIS R18, R19, R18 STL R18, 4(R17) BR L$1 Figure 7: Fortran example of Aligned (data1.order_number) and Unaligned Data (data1.item_number) References Figure 10 contains a simple program and the output from DEBUG using the SET OUTPUT LOG command. #include #include main( ) { char *p; long *lp; /* malloc returns at least quadword aligned pointer */ p = (char *)malloc( 32 ); /* construct unaligned longword pointer and place into lp */ lp = (long *)((char *)(p + 1)); /* load data into unaligned longword */ lp[0] = 123456; printf( "data = %d\n", lp[0] ); return; } ----------- Compile and Link commands -------- $ cc/debug debug_example $ link/debug debug_example $ run debug_example ----------- DEBUG session using set output log ------------ Go !break at routine DEBUG_EXAMPLE\main ! 598: p = (char *)malloc( 32 ); set break/unaligned_data set break/exception set radix hexadecimal Go !Unaligned data access: virtual address = 003CEEA1, PC = 00020048 !break on unaligned data trap preceding DEBUG_EXAMPLE\main\%LINE 602 ! 602: printf( "data = %d\n", lp[0] ); ex/inst 00020048-4 !DEBUG_EXAMPLE\main\%LINE 600+4: STL R1,(R0) ex r0 !DEBUG_EXAMPLE\main\%R0: 00000000 003CEEA1 Figure 10: DEBUG Session Showing Breakpointing at Unaligned Data Exceptions