Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

SIC-1 Solutions

Forum for posting SIC-1 solutions · By jaredkrinke

Reverse sequence

A topic by jaredkrinke created Jan 25, 2022 Views: 194 Replies: 1
Viewing posts 1 to 2
Developer

Very similar to the "stack memory" puzzle, just with handling lists' zero terminators:

@start:
subleq @tmp, @IN
subleq @tmp2, @tmp, @end
subleq @arg, @tmp
@stack_push:
subleq @stack, @arg
subleq @stack_push, @n_one
subleq @count, @n_one
subleq @arg, @arg
subleq @tmp2, @tmp2
subleq @tmp, @tmp, @start
@end:
subleq @tmp, @tmp
subleq @tmp, @stack_push
subleq @stack_pop_read+1, @stack_pop_read+1
subleq @stack_pop_read+1, @tmp
@stack_pop:
subleq @count, @one, @reset
subleq @stack_pop_read+1, @one
@stack_pop_read: subleq @OUT, @stack
subleq @tmp, @tmp, @stack_pop
@reset:
subleq @OUT, @zero
subleq @count, @count
subleq @count, @n_one
subleq @tmp2, @tmp2
subleq @tmp, @tmp, @start
; Constants
@zero: .data 0
@one: .data 1
@n_one: .data -1
; Variables
@tmp: .data 0
@tmp2: .data 0
@count: .data 1
@arg: .data 0
@result: .data 0
@stack: .data 0

Developer

Additional commentary:

  • The value is read into "@tmp" so that I can check to see if it's zero (i.e. the end of a list)
  • The second line after "@stack_push" ("subleq @stack_push, @n_one") increments the destination address of the operation, so next time the item will be written to the next larger address
  • "@end" is when the end of the list is encountered and it copies the stack address (which happens to be at "@stack_pop+0", i.e. just "@stack_pop") to the write address of the instruction at "@stack_pop_read" (i.e. "@stack_pop_read+1")
  • That address is then decremented each time through the loop ("subleq @stack_pop_read+1, @one")
  • The zero terminator is written with the first line of "@reset" ("subleq @OUT, @zero")