Page 1 of 1

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

Posted: Sat Dec 21, 2024 1:27 am
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'

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

Posted: Sat Dec 21, 2024 9:17 am
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.

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

Posted: Sat Dec 21, 2024 11:08 am
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

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

Posted: Sat Dec 21, 2024 2:11 pm
by Carsonnetic
Thank you!