Hi,
I am no sure cause its been a long time since I studied about this.
The basic routine that happens is
Code-(compilation)->Assembly Language-(Assembler)->Object code
Object Code is the closeset representation of computer code.
There is another step of mapping that happens where the actual code for the computer in 1's and 0's is formed.
Hope it helped.
Peace out.
2006-10-03 05:57:23
·
answer #1
·
answered by Pradyumna N 2
·
0⤊
0⤋
Compilers are interesting programs. Their purpose is basically to take a single input (source code) and produce a single output (machine code). This sounds easy enough, and it is, but what happens inside is a bit complex.
We'll start out with a simple example. Say you have this program in some made-up language:
//////
main( String[ ] args ) {
int x;
x = 3 + 4;
}
//////
The compiler's first job is to build a structure to hold this code in some manegable way. The most common way is that a symbolic tree is built to represent the whole program. For example, there might be a part of the tree which looks like this:
X
|
=
|
+
/ \
3 4
where 3 and 4 are leafs on the tree. Each statement would look something like this. If the compiler doesn't understand the source code and can't build this tree you get a "syntax error" of some type.
Now that we have this representation of the program in memory, the different parts are identified: statements, variables, literals, etc. Piece by piece these parts are put into machine language (or assembly language, or some other usable form). When the process is complete for the whole tree, then you have your executable program.
The other part of compilers is much harder: optimization. That is WAYYY to complicated to get into here.
I would suggest you go look at a couple books, or audit a college class (or a few, actually) if you're serious about this. At my alma mater the courses were called "Fundamentals of Programming Languages" and "Compilers". These were 4000 (senior) level undergraduate classes - definitely not for the casual hobbyist.
2006-10-03 06:08:36
·
answer #2
·
answered by APHawkes 2
·
0⤊
0⤋
This is not a basic question.
In fact it's a common semester long course when working toward a bachelor's degree.
There are many things that happen for a compiler to convert the code to machine language.
2006-10-03 05:56:58
·
answer #3
·
answered by irishtek 6
·
0⤊
0⤋
Several steps r involved from the stage of writing a C-program to the stage of getting it executed. I'm writing those steps sequentially --
[Step# 1] :
U've typed a C-program(as u know C is a HLL i.e. high level language) & save it by pressing F2 key as say, PROG.C. When u save it, at that time TEXT-EDITOR takes ur typed program as input & gives a C-source code containing program & processor commands (saved PROG.C) as output.
[Step# 2] :
Then the PREPROCESSOR takes that C-source code file (PROG.C) as input & gives an expanded source code (PROG.I) as output, that contains preprocessing commands properly sorted out.
[Step# 3] :
After that the COMPILER takes PROG.I as input & produces relocatable object code (PROG.OBJ) as the output.
[Step# 4] :
The LINKER takes relocatable object code (PROG.OBJ) & the standard C-library functions as input & links each-other, then the resultant executable code gets stored in PROG.EXE, that LINKER gives as output. This PROG.EXE is written in MLL i.e. machine level language.
I'm repeating the outline-points once more :
TEXT-EDITOR(produces PROG.C)
^
|
|
PREPROCESSOR(takes PROG.C as input,produces PROG.I as output)
^
|
|
COMPILER(takes PROG.I as input,produces PROG.OBJ as output)
^
|
|
LINKER(takes PROG.OBJ as input ,produces PROG.EXE as output).
Hope above points'll help u. If u want more details, u can contact me via mails. Bye...
2006-10-03 18:35:34
·
answer #4
·
answered by Innocence Redefined 5
·
0⤊
0⤋
Basically u are questioning the work of a compiler, right ?
I think the following link will help to understand better :
http://www.newton.dep.anl.gov/askasci/comp99/CS066.htm
2006-10-03 05:58:04
·
answer #5
·
answered by Mrudu 1
·
0⤊
0⤋
Here is an example from my compiler, maybe this will help you refine your question.
************ C Code ******************
27 void putcoms( struct portinfostr xdata *port, void xdata *buf, unsigned int len)
28 {
29 1 unsigned char xdata *pt = buf;
30 1 while ( len-- != 0 ) putcom( port, *(pt++));
31 1 }
********* Assembled Code of above **************
; FUNCTION _putcoms (BEGIN)
; SOURCE LINE # 27
0000 8E00 R MOV port,R6
0002 8F00 R MOV port+01H,R7
0004 8A00 R MOV len,R2
0006 8B00 R MOV len+01H,R3
;---- Variable 'buf' assigned to Register 'R4/R5' ----
; SOURCE LINE # 28
; SOURCE LINE # 29
0008 8C00 R MOV pt,R4
000A 8D00 R MOV pt+01H,R5
000C ?C0001:
; SOURCE LINE # 30
000C E500 R MOV A,len+01H
000E 1500 R DEC len+01H
0010 AE00 R MOV R6,len
0012 7002 JNZ ?C0347
0014 1500 R DEC len
0016 ?C0347:
0016 4E ORL A,R6
0017 601A JZ ?C0003
0019 0500 R INC pt+01H
001B E500 R MOV A,pt+01H
001D AE00 R MOV R6,pt
001F 7002 JNZ ?C0348
0021 0500 R INC pt
0023 ?C0348:
0023 14 DEC A
0024 F582 MOV DPL,A
0026 8E83 MOV DPH,R6
0028 E0 MOVX A,@DPTR
0029 FD MOV R5,A
002A AF00 R MOV R7,port+01H
002C AE00 R MOV R6,port
002E 120000 E LCALL _putcom
0031 80D9 SJMP ?C0001
; SOURCE LINE # 31
0033 ?C0003:
0033 22 RET
; FUNCTION _putcoms (END)
2006-10-03 06:01:31
·
answer #6
·
answered by rscanner 6
·
2⤊
0⤋
Wasn't it easier to ask google, than to type all that up?
2006-10-03 06:05:56
·
answer #7
·
answered by Gentle Dragon 5
·
0⤊
0⤋