BSS

From Esolang
Jump to navigation Jump to search

BSS is an assembly-style esoteric programming language created by User:CatLooks. It has a lot of common with 6502 Assembly and requires source code to be compiled for execution.

Limitations

There are some limitations in BSS:

  • Compiled File (ROM) must be less/equal than 32Kb.
  • RAM is 8192 bytes.
  • WRM is 16384 bytes.
  • Stack is limited to 128 addresses.
  • All registers are 8-bit (with some exceptions).

Execution

Registers

BSS has 7 registers to work with:

  • A - Accumulator
  • B - Buffer
  • X - Index
  • I - Instruction Pointer
  • P - Status
  • S - Stack Pointer
  • D - Destination Index

Address Space

BSS has 16-bit address space, which is divided into sections:

  • $0000 - $1FFF RAM (where you store all your calculations)
  • $4000 - $7FFF WRM (same as RAM, but you can save its state via savefile)
  • $2000 - $3FFF Register Space
  • $0100 - $01FF Stack (located in RAM)
  • $8000 - $FFFF ROM (your code file, filler byte is $00)

Opcodes

BSS has 32 opcodes with values $00 - $1F. Codes used here:

  • # - direct byte
  • a - address
  • a, x - address shifted by X
  • [d], x - indirect destination shifted by X
Syntax Opcode Size Description
lda # $00 2 Load a byte to A
lda a $01 3 Load a byte to A at address
lda a, x $02 3 Load a byte to A at address shifted by X
lda [d], x $0F 2 Load a byte to A at address located at D
ldx # $10 2 Load a byte to X
ldx a $03 3 Load a byte to X at address
sta a $11 3 Store a value in A to address
sta a, x $12 3 Store a value in A to address shifted by X
sta [d], x $1F 1 Store a value in A to address located at D
stx a $13 3 Store a value in X to address
txx $14 2 Transfer register 1 value to register 2
and $04 1 A = A and B
ora $05 1 A = A or B
xor $15 1 A = A xor B
lsr $07 1 A = A >> 1
lsl $17 1 A = A << 1
add $08 1 Adds B to A
sub $18 1 Subtracts B from A
adc $09 1 Adds Carry to A
sbc $19 1 Subtract Carry from A
inx $06 1 Increase X
dex $16 1 Decrease X
cmp $1A 1 Compare A to B
jmp a $0A 3 Jump to address
bne a $0B 3 Jump to address if Zero flag is clear
beq a $1B 3 Jump to address if Zero flag is set
bcc a $0C 3 Jump to address if Carry flag is clear
bcs a $1C 3 Jump to address if Carry flag is set
bsc a $0D 3 Jump to address if last branch was successful
bss a $1D 3 Jump to address if last branch failed
jsr a $0E 3 Jump to subroutine
rts $1E 1 Return from subroutine

Also, some commands can change the status register.

  • If the command is working with register value (loading, modifying), then Zero flag will be set if result value is zero.
  • Some commands can modify Carry flag as overflow. These commands are: lsr, lsl, add, sub, adc, sbc, inx, dex
  • The cmp command always modifies Zero and Carry flag (Carry flag is set when A < B).

Indirect Registers

As you know, there is 7 core registers (A, B, X, S, P, I, D). However, with this setup you couldn't do anything but write some values in the RAM or WRM. So, there are a few indirect registers than can be accessed via reading / writing to specific address.

I/O

This register allows you to write and read from console.

 $2000 - I/O Data (r/w)
 
 When written to, displays an ASCII character in console.
 When read, halts until an input, returns a value of pressed key.