home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1996
/
ARCHIVE_96.iso
/
discs
/
mag_discs
/
volume_7
/
issue_06
/
crossley
/
PROGXMPL
Wrap
Text File
|
1994-02-07
|
3KB
|
73 lines
/* C program for an example of compilation, not an example for */
/* a discussion of C programming */
/* > c.test */
#include <stdio.h>
#include "time.h"
int main()
{
int a,i;
double ra=12.5,rb ;
printf("%d ",clock());
for(i=1;i<=10000000;i++) {
ra=i ;
rb=ra*ra ;
printf("%e ",rb);
}
printf("%d\n",clock());
}
/*
Part of the final program in machine code with its assembler code,
some of the lines have been commented to show their relation to the
C code, note that this is only a fragment of the executable code.
A discussion of mixed high and low level programs could form
a third article (Editor willing) but I do not want to go more deeply
into the subject at this time.
machine code assembly language ; comment
: E1A0C00D : MOV R12,R13
: E92DD870 : STMDB R13!,{R4-R6,R11,R12,R14,PC} ; save some registers
: E24CB004 : SUB R11,R12,#4
: E15D000A : CMP R13,R10
: BB0000C0 : BLLT &000083A8 ; check stack space
: EB0000D8 : BL &0000840C ; get time
: E1A01000 : MOV R1,R0
: E28F0F14 : ADR R0,&00008104
: EB0000D2 : BL &00008400 ; print it
: E3A05001 : MOV R5,#1 ; initial value in counter
: E3A06D5A : MOV R6,#&1680 ; =5760
: E2866502 : ADD R6,R6,#&00800000 ; put 10000000 in counter
: E2866962 : ADD R6,R6,#&00188000 ; maximum
: E3A04000 : MOV R4,#0
: EE005190 : FLTD R5,F0 * ; put counter into fp register
: EE100180 : MUFD F0,F0,F0 ; multiply
: ED2D8102 : STFD F0,[R13,#-8]! ; store result, 2 words
: E28F0F0C : ADR R0,&0000810C ; get address of format stmnt
: E8BD0006 : LDMIA R13!,{R1,R2} ; get 2 words of result
: EB000108 : BL &00008504 ; print it
: E2855001 : ADD R5,R5,#1 ; inc the counter
: E1550006 : CMP R5,R6 ; reached max ?
: DAFFFFF6 : BLE &000080C8 ; no, go to start of loop at *
: EB0000C6 : BL &0000840C ; yes, get time
: E1A01000 : MOV R1,R0
: E28F0F06 : ADR R0,&00008114
: EB0000C0 : BL &00008400 ; print the result
: E1A00004 : MOV R0,R4
: E95BA870 : LDMDB R11,{R4-R6,R11,R13,PC}^ ; retreive the registers
: 20206425 : ; '%d ' format
: 00000020 : ANDEQ R0,R0,R0,LSR #32
: 20206525 : ; '%e ' format
: 00000000 : ANDEQ R0,R0,R0
: 000A6425 : ; '%d<crtrtn> format
The reader will notice that there are many extra lines which
have nocounterpart in the C program, in addition the source code
uses 2 floating point variables 'ra' and 'rb' and an integer
'a' but only one floating point variable appears in the final
program, in F0 and 'a' also has gone. This is an example of the
compiler being efficient.
*/