little help w/ 816 assem if possible :)

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
Tancor
Posts: 113
Joined: 18 Dec 2002
Contact:

little help w/ 816 assem if possible :)

Post by Tancor »

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
TMorita
Posts: 217
Joined: 15 Sep 2002

Post by TMorita »

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
TMorita
Posts: 217
Joined: 15 Sep 2002

Post by TMorita »

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
Tancor
Posts: 113
Joined: 18 Dec 2002
Contact:

Post by Tancor »

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
TMorita
Posts: 217
Joined: 15 Sep 2002

Post by TMorita »

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
Post Reply