![]() |
|
|
|
|
|
|
3
31st October 20:54
External User
Posts: 1
|
Since they are constants, you don't need to do anything with them,
except use them in instructions: 1 FOR I = 1 TO 9 STEP 2 L00001: mov ax,0001h ** load initial value jmp I00003 ** goto to exit check 2 A = A + 1' do statememt I00004: L00002: inc A% 3 NEXT I L00003: mov ax,I% ** increment after statement add ax,0002h I00003: mov I%,ax ** save I cmp ax,0009h ** check for done jng I00004 ** loop again It gets tricky when everything is a variable :-) 5 FOR I = A1 TO A9 STEP A2 L00005: mov ax,A9% mov t000C%,ax ** save ending value mov ax,A2% mov t0010%,ax ** save step value mov ax,A1% ** set initial value jmp I00005 6 A = A + 1' do statememt I00006: L00006: inc A% 7 NEXT I L00007: mov ax,t0010% ** increment after statement add ax,I% I00005: mov I%,ax ** save I (based of sign of step var, see if you are done) cmp word ptr t0010%,00h jnl I00007 cmp ax,t000C% jnl I00006 jmp I00008 I00007: cmp ax,t000C% jng I00006 -- Arargh312 at [drop the 'http://www.' from ->] http://www.arargh.com BCET Basic Compiler Page: http://www.arargh.com/basic/index.html To reply by email, remove the garbage from the reply address. |
|
|
4
31st October 20:54
External User
Posts: 1
|
You should take a look at the chapter on implementing
low-level control structures in "The Art of Assembly Language" (http://www.nostarch.com and http://webster.cs.ucr.edu). It will tell you how to convert most high-level control structures into low-level machine code. Cheers, Randy Hyde |
|
|
9
10th November 05:51
External User
Posts: 1
|
Your compiler has to be able to handle temporaries. You're dividing the
code into basic blocks and building a directed graph, right? You know at any time how many temporaries you're tracking. When you start to generate assembler code (which you won't do until you parse the graph later), you'll keep the temporaries in registers until you run out of free registers, then you'll start dumping them to memory on the stack. Are you using yacc or ANTLR to generate your compiler? -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. |
|
|
10
10th November 05:51
External User
Posts: 1
|
So it's a register allocation problem? Read about graph coloring.
There's an explanation of it in the Dragon Book, but I think the Tiger Book by Andrew Appel might have a better description. It's a matter of creating code that evaluates expressions into virtual registers, and then figuring out which actual registers are available at any given time and chosing which values to spill onto the stack and so forth. But you said that you pretend the processor is a stack machine - still, the result of the expression in the test doesn't need to be stored between the iterations, does it? It's recalculated each time round. Or is there something with this language that isn't obvious that we should know? Or am I missing something...? -- Remove the furry animal from my address to send email: bjarni.ferret@update.ferret.uu.se |
|