|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
|
Listing 1-A comparison of C code, 68K, and 21K assembly code to calculate the sum of the first three elements of a 10-element array. C code segment int values[10]; int sum = 0; int *pt = values; for (count = 0; count < 3; count++) sum = sum +*pt++; 68K code segment section data VALUES: DS.L 40 section code // Clear the sum variable MOVE.L #0, D0 // Set up the pointer to the array MOVE.L #VALUES, A0 // Calculate the sum ADD.L (A0)+, D0 // Fetch, add ADD.L (A0)+, D0 // and increment ADD.L (A0)+, D0 // A0 pointing to VALUES[3] 21K code segment .segment/dm seg_dmda; .var VALUES[10]; .endseg; .segment/pm seg_pmco; // Clear the sum variable R0 = 0; // Set up the pointer to the array I4 = VALUES; // Set up address modify constant M4 = 1; // Calculate the sum R1 = dm(I4, M4); // Fetch R0 = R0 + R1; // and add R1 = dm(I4, M4); // Fetch R0 = R0 + R1; // and add R1 = dm(I4, M4); // Fetch R0 = R0 + R1; // and add // I4 pointing to VALUES[3];
|
|||||||||||||||||||||||||||||||||
|
Copyright © 2003 ChipCenter-QuestLink About ChipCenter-Questlink |
||||||||||||||||||||||||||||||||||