Quick post: Determining length in Commodore Assembly

Quick post: Determining length in Commodore Assembly

A common task in our code is to determine the length of something. In this example, let's check the length of a string like "are you keeping up?"

In Python, this is crazy easy.

#!/usr/bin/env python

message = "are you keeping up?"

Python 3

In 6510 Assembly, this is also easy. Not crazy easy, but straightforward anyway.

	ldx #$00
	lda message,x
	cmp #$00 ; or whatever we're using as a delimeter
    	beq done
    	jmp checkdel
	stx messagelen
.byte messagelen 0

message .null "are you keeping up?"
Turbo Macro Pro

Pretty easy right?

This assumes some sort of sane delimiter. In this case we're checking for zero, which the .null directive in Turbo Macro Pro appends to the end of the string.

This works well as long as you don't need the "@" PETSCII screencode which is zero on the Commodore. For these things I usually stick to ASCII so using zero is a sensible delimiter for me.

Happy Coding!