SASM

From Esolang
Jump to navigation Jump to search

SASM is a very simple derivative of assembly code.

Commands

Aperçu

Command Effect
mov destination, source Assigns the source to the destination. The destination may be a register or [bx]; the source may be a literal integer, a register, or [bx].
add destination, source Increments the destination by the source. The destination may be a register or [bx]; the source may be a literal integer, a register, or [bx].
sub destination, source Decrements the destination by the source. The destination may be a register or [bx]; the source may be a literal integer, a register, or [bx].
cmp left, right, destination Compares the left and the right operand; if both are equal, the destination is set to 1, otherwise it is set to 0. The left and right operand may be a literal integer, a register, or [bx]; the destination may be a register or [bx].
je left, right, tag Compares the left and the right operand; if both are equal, the instruction pointer (IP) is relocated to the tag; otherwise no effect ensues. The left and right operand may be a literal integer, a register, or [bx]; the tag must be the name of a tag (label) defined in the program.
jne left, right, tag Compares the left and the right operand; if both are not equal, the instruction pointer (IP) is relocated to the tag; otherwise no effect ensues. The left and right operand may be a literal integer, a register, or [bx]; the tag must be the name of a tag (label) defined in the program.
tag: Defines a goto tag (label) with the name tag, which must be a valid identifier.

mov

It is just the = command in C. It sets a register (ax, bx, cx, dx) to a value, or sets a register to another register's value. But, BX can address the place(only BX can do that) by []s. Like [bx]. It can set an address to a register.

mov bx,dx
mov ax,[bx]

cmp

It compares two things.

cmp ax,bx,cx

Sets cx to 1 if ax = bx, 0 otherwise.

je

It means "Jump if equal" to a tag name in the selections.

jne

It means "Jump if not equal" to a tag name in the selections.

add

It means "Make the first register increment by the register or a value".

sub

It is equivalent to add, but it subtracts it.

Last but not least

It has tags, like this:

mytag:
    ...

Examples

Countdown

This program counts down from ten (10) to zero (0):

mov ax, 10
mov bx, ax

countdown:
  sub bx, 1
  jne bx, 0, countdown

Indirect addressing

The following code stores the value 100 at the memory address 2:

mov bx, 2
mov [bx], 100

Truth-machine

This program approximates a truth-machine. An input of zero (0) is simulated by choosing an initial program memory whose first cell, at the address 0, contains 0; an input of one (1), ensuing similiter, issues from a value of 1 at the address 0:

je [bx], 0, _halt

_goback:
  add bx, 1
  mov [bx], 1
  je [bx], 1, _goback

_halt:

Interpreter

  • Common Lisp implementation of the SASM programming language.