Hi all,
If you've followed my other post about lcc, you know that I'm converting it from outputting for orca/m to cross-32.
To do this, I need to modify the dag files that relate to code generation (and a little bit of source fiddling to handling things like data assignments).
Here is the C source (yes, it's an utterly useless program, but it was quick, short and displayed a few ??'s in assembly):
main ()
{
int i = 50;
int z;
z = i+4;
if (z>5)
z=0;
else
z=1;
}
Here is the assembler output - I'll put comments in with // to describe what I know is going on and where I am confused...
// no problem here - start of the program, positioning variables in memory - would still
// like to know where this is done in the source of dag2gs2 as it appears to like to put
// variables into the initial 256 bytes of 0 page, and I'd like to reserve banks of it for
// other purposes.
; STARTFUNC(%0),(_main)
_main start
_z: equ 1
_i: equ 5
//??????????????
// Not sure what this block is for. Taking a guess, this is for something with relocation,
// but I am not sure what the significance of memory location R15 is. Obviously R15 isn't
// defined, I couldn't find any reference to it so far in the Orca/m manual, so it almost
// looks like it is something that is defined between this output and the final compile,
// but I am not sure of the importance of the numbers - almost appears to be attempting to figure
// a starting point for the code and an offset...
dag_temp_start: equ 9
gen_temp_start equ dag_temp_start+0
local: equ gen_temp_start+-1
; LINK(),()
lda r15
add.l #-local
sta r15
// This portion is obvious - just assigning a value to int i
; ASGNI(CNSTI(%0),ADDRLP(%1)),(50,_i)
lda.l #50
sta <_i
stx <_i+2
// Another obvious section - loading i into the accumulator, adding 4 to it and storing that value in z.
; ASGNI(ADDI(CNSTI(%0),INDIRI(ADDRLP(%1))),ADDRLP(%2)),(4,_i,_z)
lda <_i
clc
adc #<4
sta <_z
lda <_i+2
adc #^4
sta <_z+2
// This portion is the if then else statement, no problem.
; LEI(CNSTI(%0),INDIRI(ADDRLP(%1)),%2),(5,_z,L2)
lda #<5
sec
sbc <_z
lda #^5
sbc <_z+2
bvc *+5
eor #$8000
bmi *+5
//??????????????????
// Here's an oddity tho - if we are dealing with relocateable code, the label for L2 has to be set
// at compile time afaik, so how can it be relocated to a new location in memory? the jmp
// will still jump to a specific memory location specified by L2??
jmp L2
// part of the if-then-else
; ASGNI(CNSTI(%0),ADDRLP(%1)),(0,_z)
lda.l #0
sta <_z
stx <_z+2
//???????????????????
// another jump that makes no sense when considering relocateable code...? You'd think it would be something
// more like jmp ($12) to have an address calculated and store in 0 page for making the jump..
; JUMPV(ADDRGP(%0)),(L3)
jmp L3
; LABELV(%0),(L2)
L2 anop
; ASGNI(CNSTI(%0),ADDRLP(%1)),(1,_z)
lda.l #1
sta <_z
stx <_z+2
; LABELV(%0),(L3)
L3 anop
//??????????????????
//conclusion - r15 is back in the picture again, but what is the importance of it?
; RETV(),()
lda r15
add.l #local
sta r15
rts
; LABELV(%0),(L1)
L1 anop
; ENDFUNC(%0),(_main)
_main end
; FLUSH(),()
end
; FLUSH(),()
As you can see, there are a few confusing things.
Granted right now, I don't need relocateable code - I'm working on creating something that is singletasking non-relocateable, but in the future I may want to have multitasking (on a small scale of course) and relocateable...
Any tips on the areas of code that I have put forth questions would be most appreciated - I'm learning a lot about lcc, but some of the code generation is a little beyond my grasp in terms of why, especially when it doesn't appear to correspond with my orca/m manual (it is the manual for orca/m for //gs).
_________________ -Tony
KG4WFX
|