I can't figure out whats wrong with my code. :(

Get technical support from the community & developers with specific X16 programs if you can't find the solution elsewhere
(for general non-support related chat about programs please comment directly under the program in the software library)
Post Reply
Carsonnetic
Posts: 2
Joined: Fri Jan 19, 2024 1:00 am

Important I can't figure out whats wrong with my code. :(

Post by Carsonnetic »

I have tried making a basic Hello World program in ASM, but it keeps hanging and I don't know why.

This is my code:

.SEGMENT "START"
JMP BEGIN
.SEGMENT "INIT"
.SEGMENT "ONCE"
.SEGMENT "CODE"

CHROUT = $FFD2

HELLOTEXT:
.BYTE "HELLO, WORLD!",13,0

BEGIN:
LDX #0
LOOP:
LDA HELLOTEXT,X
BEQ DONE
JSR CHROUT
INX
BRA LOOP
DONE:
LDA 13
JSR CHROUT
RTS

Does anyone know what's wrong with the code?
Sorry about this, but this is my first time coding in ASM.

P.S. This may not be useful, but when I assembled this code, it threw up an error code and I can't figure out what it means.

"ld65: Error: Missing memory area assignment for segment 'START'
TomXP411
Posts: 1808
Joined: Tue May 19, 2020 8:49 pm

Re: I can't figure out whats wrong with my code. :(

Post by TomXP411 »

You need a program counter directive.
That's usually * = or ORG, depending on the assembler.

ORG $400
or
* = $400

Also... it would help to tell us which assembler you are using.
Stefan
Posts: 465
Joined: Thu Aug 20, 2020 8:59 am

Re: I can't figure out whats wrong with my code. :(

Post by Stefan »

The ld65 error gives away that you're using the ca65 assembler from the cc65 project.

That ld65 (linker) error suggests that you are not using a proper command when assembling. I recommend that you use this command:

Code: Select all

cl65 -o HELLO.PRG -t cx16 -C cx16-asm.cfg -u __EXEHDR__ hello.asm
, where -o is the name of the resulting file, -t is the computer type, -C is the config file for X16 assembly, -u adds a BASIC stub at the beginning of the code so that you can run it, and hello.asm is the name of the source file.

I also recommend that you clean up the code a bit, removing memory segments not normally used in assembly programs. The resulting code could be like this, where all code ends up in the default CODE segment:

Code: Select all

JMP BEGIN

CHROUT = $FFD2

HELLOTEXT:
.BYTE "HELLO, WORLD!",13,0

BEGIN:
LDX #0
LOOP:
LDA HELLOTEXT,X
BEQ DONE
JSR CHROUT
INX
BRA LOOP
DONE:
LDA 13
JSR CHROUT
RTS
Carsonnetic
Posts: 2
Joined: Fri Jan 19, 2024 1:00 am

Re: I can't figure out whats wrong with my code. :(

Post by Carsonnetic »

Thank you!
Last edited by Carsonnetic on Sat Dec 21, 2024 2:16 pm, edited 1 time in total.
Post Reply