Jump to content
  • 0
konzill

Assembler Hello World

Question

Does anyone know if there is an Assembly language hello world sample for the X16. Something that just prints hello world on the screen in the built in font.  I've done this on c64 but I'm getting confused trying to work out how to move it to x16. 

Edited by konzill

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

The program should be the same as long as you use kernel routines to print the text (CHROUT). What are you struggling with?

Share this post


Link to post
Share on other sites
  • 0

Looping code to print 'Hello' at memory location $1500

.A 1000 LDX #$00
.A 1002 LDA $1500,X
.A 1005 JSR $FFD2
.A 1008 INX
.A 1009 CPX #$06
.A 100B BNE $1002
.A 100D RTS

Have to load $1500+ with HELLO = 48 45 4C 4C 4F OD

To call from Basic: SYS 4096 OR SYS $1000

$93 = Clear Screen

  • Like 2

Share this post


Link to post
Share on other sites
  • 0

In a perfect coincidence, I just created a Hello World repo exactly for the purpose of helping folks use the cc65 tool chain. I have examples in assembly, C, and a mix of both. And the README goes through the whole setup and build process in detail. Get started here:

https://github.com/SlithyMatt/x16-hello-cc65

I'm going to be making a video going through it very soon. It may be up as early as tonight.

  • Like 4

Share this post


Link to post
Share on other sites
  • 0
20 hours ago, John Federico said:

Looping code to print 'Hello' at memory location $1500


.A 1000 LDX #$00
.A 1002 LDA $1500,X
.A 1005 JSR $FFD2
.A 1008 INX
.A 1009 CPX #$06
.A 100B BNE $1002
.A 100D RTS

Have to load $1500+ with HELLO = 48 45 4C 4C 4F OD

To call from Basic: SYS 4096 OR SYS $1000

$93 = Clear Screen

And with very little change, you can get 00 terminated strings. This gives you a string routine that can print strings of any length between 0 and 255 bytes. 

org $1000
  LDX #$00        ;set string position to 0
.loop
  LDA $1500,X  ;read byte from string @position
  BEQ end          ;if Value is 00 end
  JSR $FFD2     ;else ... print char
  INX                  ;next character in the string
  BNE loop        ;jump back as long as X is not 0 again ... (means max string length is 256 bytes including the termination string).       
.end
  RTS

org $1500
!byte $48,$45,$4C,$4C,$4F,$0D,$00  ; "HELLO<CR><STRTERM>"
If you put it directly into the monitor, you need to first assemble the stuff with some placeholder addresses and then check for the correct addresses of loop and end to insert the correct address in the BEQ and BNE commands. Or you use ca65 ... or any other assembler, it does it for you.

  • Like 2

Share this post


Link to post
Share on other sites
  • 0
On 9/15/2020 at 9:14 AM, John Federico said:

Looping code to print 'Hello' at memory location $1500


.A 1000 LDX #$00
.A 1002 LDA $1500,X
.A 1005 JSR $FFD2
.A 1008 INX
.A 1009 CPX #$06
.A 100B BNE $1002
.A 100D RTS

Have to load $1500+ with HELLO = 48 45 4C 4C 4F OD

To call from Basic: SYS 4096 OR SYS $1000

$93 = Clear Screen

So the routine doesn't touch X? I never know off the top of my head which Kernel routines trash X/Y and which don't.

Share this post


Link to post
Share on other sites
  • 0
2 hours ago, BruceMcF said:

So the routine doesn't touch X? I never know off the top of my head which Kernel routines trash X/Y and which don't.

Nope, X and Y are untouched. I use this for a reference: https://sta.c64.org/cbm64krnfunc.html

It's not 100% accurate, especially with the X16 kernal, but it's close enough. In the case of the X16 kernal code, X and Y are automatically preserved on the stack.

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
11 hours ago, BruceMcF said:

So the routine doesn't touch X? I never know off the top of my head which Kernel routines trash X/Y and which don't.

I've kinda figured that out and wrote it down in the kernel subroutines definition list for prog8 (because the compiler needs that information).  You can find it here https://github.com/irmen/prog8/blob/master/compiler/res/prog8lib/cx16lib.p8#L19

Look for the "clobbers" clause, if it's there it tells you what registers get clobbered.    Maybe this is of some help to you

(It's only correct for the "default" kernel routines that are compatible with the C64, I haven't yet made proper clobber lists in this file for the new Cx16 kernel calls)

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
20 hours ago, SlithyMatt said:

Nope, X and Y are untouched. I use this for a reference: https://sta.c64.org/cbm64krnfunc.html

It's not 100% accurate, especially with the X16 kernal, but it's close enough. In the case of the X16 kernal code, X and Y are automatically preserved on the stack.

That's the same one I used for the behavior, but it was GETIN that was cobblering my data stack (X) and inner interpreter (Y) not CHROUT ... I can speed up my chrout routine by 12 clocks.

Edited by BruceMcF

Share this post


Link to post
Share on other sites
  • 0

I am silly.  That reference you both mention is also what I initially used to create my clobber-list.  So I think you can safely ignore my derived specification file 🙂

Share this post


Link to post
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.

Guest
Answer this question...

×   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.


×
×
  • Create New...

Important Information

Please review our Terms of Use