6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 1:26 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 11, 2005 3:53 am 
Offline

Joined: Wed Dec 18, 2002 3:20 am
Posts: 113
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 12, 2005 6:55 pm 
Offline

Joined: Sun Sep 15, 2002 10:42 pm
Posts: 214
I'm beginning to think I packaged an earlier version.

There should be a TCD in there somewhere, like this:

lda r15
add.l #-local
sta r15
tcd

This moves all the locals onto the stack.

The label _local should be defined in there somewhere too.

The code generator works by fooling lcc into thinking there's a 32-bit processors with 16 registers.

I think I allocated R0-R15 somewhere in non-zero-page memory.

Sorry about the vague answers - I last worked on this code about 9 years ago. I'll try to post more after I finish my work for today.

Toshi


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat May 14, 2005 7:01 pm 
Offline

Joined: Sun Sep 15, 2002 10:42 pm
Posts: 214
Sorry, I haven't forgotten this.

The "little abdomen pain" I was feeling on Thursday wound up getting worse, and I developed a fever, and I had to go to the hospital for some tests.

I'll try to look at this this weekend.

Toshi
h


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat May 14, 2005 7:47 pm 
Offline

Joined: Wed Dec 18, 2002 3:20 am
Posts: 113
No problem Toshi,

Take care of yourself first, this isn't nearly as important, and definitly not life threatening ;).

I hope you feel better!

_________________
-Tony
KG4WFX


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 15, 2005 3:43 am 
Offline

Joined: Sun Sep 15, 2002 10:42 pm
Posts: 214
The macro

LINK()
lda r15
add.l #-local
sta r15

needs to be changed to:

LINK()
lda r15
add.l #-local
sta r15
tcd

Unfortunately, it looks like I forgot to include the macro file which defines various macros such as lda.l, add.l, exts.b, and extu.b.

I think I can supply definitions if you're really interested in using it.

Toshi


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: DRG and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: