Jump to content
  • 0

Assembler Hello World


konzill
 Share

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
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 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 5
Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 0

I've been away far too long and so much has happened here... let me resurrect this old thread and give an easy straightforward answer since I migrated to a new tiny and compact 6502 compiler "xa" (only 106K) from the bloated cc65 suite. Obviously, the first thing to do is write a "hello world" program (Please forgive my blatant plagiarism of SerErris' code above):

Quote

 

; This program simply prints "HELLO"

CHROUT = $ffd2

    .byt $01, $08, $0C, $08, $0A, $00, $9E, $20
    .byt $32, $30, $36, $34, $00, $00, $00, $00
    .byt $00

*=$0810   ; starting address of the program

start    LDX #$00        ; set string position to 0
loop    LDA string,X    ; read byte from string @position
      BEQ end        ; if value is 00 end
      JSR CHROUT         ; else print char
      INX        ; next character in the string
      BNE loop        ; jump back as long as X is not 0 again, max string length is 256 bytes
end
    RTS

string    .byt $48,$45,$4C,$4C,$4F,$0D,$00      ;"HELLO<CR><STRTERM>"

 

Compile this with:

xa -v hello.a65 -o hello.prg

Execute with:

x16 -run -prg hello.prg

Enjoy! (If someone knows how to post a properly formatted code let me know, above looks so messy without fixed-width fonts)

Edited by geek504
Link to comment
Share on other sites

  • 0
  • Super Administrators
On 6/22/2022 at 1:22 PM, geek504 said:

I've been away far too long and so much has happened here... let me resurrect this old thread and give an easy straightforward answer since I migrated to a new tiny and compact 6502 compiler "xa" (only 106K) from the bloated cc65 suite. Obviously, the first thing to do is write a "hello world" program (Please forgive my blatant plagiarism of SerErris' code above):

Compile this with:

xa -v hello.a65 -o hello.prg

Execute with:

x16 -run -prg hello.prg

Enjoy! (If someone knows how to post a properly formatted code let me know, above looks so messy without fixed-width fonts)

Welcome.

I prefer 64TASS myself, partly because of the quality of its documentation, but also because it's portable and easy to use. I'm glad there are so many choices for 6502 assemblers; there's something to match everyone's needs. 😃

 

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.

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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use