Assembly But Worse

From Esolang
Jump to navigation Jump to search

Welcome to Assembly But Worse! A worse version of assembly language made by the genius himself, User:WoodyFan3412
The language is heavily inspired by Assembly Language.

A program written in Assembly But Worse.
Pre Processer Directives.

Memory

when the program is started, a list with 3,000 values (3 kb) is initalized to 0, the program can read and write from this list of values
the program can also use a stack

Program Info


Registers
Name Purpose Default
X Index X 0
Y Index Y 0
A The accumulator, any math operations will use this value. 0
PC Program Counter 1
Z Is set to 1 if the accumulator is 0, is set to 0 otherwise. 1
Instructions
Name Opcode Operands Description
goto 0 <label> Sets the program counter to this location in the code
call 1 <subroutine> Pushes a return address onto the stack and sets the program counter to this location in the code
ret 2 Returns to the value on the top of the stack, this also allows for subroutines to be nested inside of eachother
return 2 Returns to the value on the top of the stack, This is an alias of 'ret'
quit 3 Quits the program
echo 4 <text> Puts this text in the console. If the argument is a register, it puts the value of the register in the console.
push 5 <register> pushes the value of this register on the stack
pop 6 <register> gets the value on the top of the stack and sets the register to that value
read 7 <address> <register> Reads a value from memory and stores it in the register
write 8 <address> <register> Writes the value of the register to this location in memory
move 9 <loc1> <loc2> move a 15 will move the value 15 into register A, move 15 10 will move the value 10 into memory 15, move a x will move the value of a into X.
inc 10 <register> changes this register's value by 1, the register can only be in the range 0 - 255 and can overflow
dec 11 <register> changes this register's value by -1, the register can only be in the range 0 - 255 and can overflow

Pre-Processing

ABW supports pre-processing, which are instructions that dictate how the source should be compiled to byte-code
Just like in C++, you can use #define to make the compiler replace a string with a value

#define HELLO "Hello, World!"
goto main

main:
  echo HELLO
  quit

; Output: "Hello, World!"


Examples

function

goto main

main:
	call Message1 ; print hello world
	call Message2 ; print my name is
	call Message3 ; print john
	quit          ; quit the program


Message1:
	echo "Hello World"
	
	; in here, returning will return to the main function
	ret

Message2:
	echo "My Name Is"
	ret

Message3:
	echo John
	return    ; return can also be used, it acts the same as ret

; Output: Hello World My Name Is John

loop 1

goto loop  ; start the loop

loop:
	echo Boom!  ; print it to the console
	goto loop   ; jump to the loop (2 lines above)

; Output: Boom! Boom! Boom! Boom! Boom! Boom! ...

loop 2 (smaller)

echo "0101"   ; print the text
goto "1"      ; goto also supports going to a line number

; Output: 01010101010101010101010101010101 ...

memory addresses

move 1 15  ; Store 15 into index 1
move 2 30  ; Store 30 into index 2
move 3 45  ; Store 45 into index 3

read 1,a
echo "a"
read 2,a
echo "a"
read 3,a
echo "a"

; Output: 15 30 45

nesting

call n1
quit

n1:
	echo "Beyond"
	call n2
	ret

n2:
	echo "The"
	call n3
	return

n3:
	echo "Horizon"
	return

; Output: Beyond The Horizon

Implementation

I only ever implemented this language in TurboWarp.