Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

SIC-1 Solutions

Forum for posting SIC-1 solutions · By jaredkrinke

Small byte optimization tip

A topic by trimute2 created Jul 27, 2022 Views: 405 Replies: 3
Viewing posts 1 to 4
(1 edit) (+1)

Not a solution but I felt that it would fit here. If your solution starts by taking an input like this


subleq @input @IN
;rest of the program

@input: .data 0

you can use one less byte by instead writing


@input: .data 0

.data @IN

.data 3

This works since the first address is 0 and as long as the value at address 0 is 0 it is going to modify itself. This only works as long as whenever that line is reached @input is equal to 0, as a bonus any byte that refrences @Input can be used as a constant for 0.

Developer

Great suggestion! Also, this optimization may make code less readable, thus ensuring continued employment ;)

(+1)

you don't actually have to make in unreadable - 'cos doing the following works just as well:

@loop:
@input:
subleq @input, @IN

the action of putting a label inside its own address already creates the right value, AND you can use multiple labels at the same address for more readability

another option is to write explicit 0 there instead:

@loop: 
@input: 
subleq 0, @IN
Developer

At some point, inline labels got added, so you can also write this (arguably more readably):

subleq @input: 0, @IN