Jump to content
IGNORED

Odd cc65 behaviour


TGB1718

Recommended Posts

I'm just testing some inline .ASM code in cc65 but getting strange results using "-1"

is this a "feature" of cc65 ?

 

I tried with local and global variables, same result.

 

this returns 0

    signed char v;

    __asm__ ("lda #-1");
    __asm__ ("sta %v",v);

    return(v);

 

This returns 25

    signed char v;

    __asm__ ("lda #25");
    __asm__ ("sta %v",v);

    return(v);

 

This returns 255 which is -1

    signed char v;
    signed char w=-1;

    __asm__ ("lda %v",w);
    __asm__ ("sta %v",v);

    return(v);

 

So does this return 255

    signed char v;

    __asm__ ("lda #255");
    __asm__ ("sta %v",v);

    return(v);

 

Link to comment
Share on other sites

maybe try: _asm__("lda #%b", -1);

 

probably something I've not tried with more recent sources as in early CA65 days the assembler wouldn't accept negative numbers, but when doing disassemblies with IDA Pro I had to manually run through and change "LDA/X/Y #-" to positive values before exporting as source.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Wrathchild said:

maybe try: _asm__("lda #%b", -1);

Yes, that fixed it, strange that it doesn't accept it in the previous format, it is a rather long winded way to put in-line assembler.

thanks very much ?

 

Some C compilers I've use in the past, mainly on my ST, all you had to do was

#asm

... your assembler code

...

#endasm

Link to comment
Share on other sites

@Wrathchild sorry to be a pain, but do you know of and examples of how to firstly use ca65 to produce runnable code,

I converted some code from MAC/65 and managed to run it through ca65, but what next, I've looked at the help files,

but struggling a bit.

 

Also how would you merge this with a C program to use with cc65.

 

There's tons of information in the manuals, but a total lack of examples

Link to comment
Share on other sites

Sounds like you might be over thinking it.

 

break a function out to a separate C file and then compile it using cc65 (not cl65) so that you just produce the .s file from it.

 

You can then examine that to get a feel of how to structure the .s file, but ultimate it really boils down to the '.export' directive to expose the things you want to access.

 

The .s file itself can be built to an object file using ca65 which can then be used with the linker.

 

But you can also use cl65 and pass multiple input files, mixing .c and .s and it will take care the rest.

 

If needed, break down what you are trying into a smaller example and PM me if you get stuck.

Link to comment
Share on other sites

Hi!

17 hours ago, TGB1718 said:

sorry to be a pain, but do you know of and examples of how to firstly use ca65 to produce runnable code,

I converted some code from MAC/65 and managed to run it through ca65, but what next, I've looked at the help files,

but struggling a bit.

 

Perhaps a minimal assembly example could help. Try this into a file named "minimal.s":

	; Export the start of program code
	.export	start

	; Include Atari equates
	.include "atari.inc"

	; Out code
	.code
start:
	ldx	#0
loop:
	stx	COLBK
	stx	WSYNC
	inx
	ldy	CH
	iny
	beq	loop
	rts

Then, you assemble with:

cl65 -tatari -Catari-asm-xex.cfg minimal.s -o minimal.xex

That is all it takes.

 

    Have Fun!

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...