From Esolang
Jump to: navigation, search

BAM128 is an esoteric programming language invented by Simone Russo (User:Eafkuor). It consists of a set of instructions to manage two pointers and a square matrix M of 128x128 elements. The two pointers (from now on called P1 and P2) contain the row and column, respectively, of the matrix element we are working on. We can modify just one of these pointers at a time. Both P1 and P2 and every matrix element can assume values in the range [0, 127].

Language overview

The commands are:

Command Description
/ Start operating on the other position register
! Switch the values contained in the position registers, but continue operating on the same one
i Input a value in M(P1, P2)
n Print the numeric value contained in M(P1, P2)
p Print the ascii character corresponding to the value contained in M(P1, P2)
*d Increments M(P1, P2) by 2^d, where d must be a digit 0<=d<=9
+d Increments the current position register by 2^d, where d must be a digit 0<=d<=9
>d Adds M(P1, P2) to the matrix element 2^d positions ahead, d must be a digit 0<=d<=9
(code) Executes the code inside the parentheses until M(P1, P2)!=0
.Comment. Comments must be put between two dots.

When looking for the matrix element n positions ahead (instruction >), if the last cell of the row is reached, P2 goes back to 0 and P1 is incremented (i.e. the search starts from the next row, following the path S in the image on the right).


Hello, World!

This is just one way to write the Hello World! program (with comments):

*6*3        .Increments M(0,0) by 2^6=64 and then by 2^3=8.
p           .Prints the ascii value of M(0,0) that is 64+8=72=H.
*4*3*2*0p   .Increments M(0,0) by 29 and prints 'e' (101). . Remember that 2^0=1.
*2*1*0pp>0  .Prints 'l' 2 times and then we copy M(0,0)  to M(0,1) for later use.
*1*0p       .Prints 'o'.

            .Now M(0,0) equals 111, and we want to print 'space' that is 32 in the ascii table.
*5*4*0p     .We incremented M(0,0) by 49 to overflow the maximum value of 127 and return back to 32.

*5*4*2*1*0p .Prints 'W'.
*4*3p*1*0p  .Prints 'or'.

/           .We operate on the column position register (the default is the row).

+0          .We increment the column position register by 1 to move to M(0,1).

p           .We print 'l', which we stored previously in M(0,1).

+0          .We move to M(0,2).

*6*5*2p     .Increment M(0,2) by 100 and print d.

+0*5*0p     .We increment M(0,3) by 33 and print it (it's '!').

Without comments:


Print ASCII Table

Program that prints the ASCII values from 33 to 127:

*5*0p .M(0,0)=33, and then prints it.

(*0p) .While(M(0,0)!=0) increment it by 1 and print the ascii value.
      .Note that when M(0,0) is 127, adding 1 to it makes it go back to 0 and end the cycle.

Without comments:


Print Numbers from 0 to 127

n     .Print 0.
*0    .M(0,0)=1.
+0*5  .Move to M(1,0) and increment it to 32 (space character in the ascii table).
+6+5+4+3+2+1+0 .Increment the column register by 127 to go back to M(0,0).
(     .Cycle start.
   n  .Print M(0,0).
   *0 .Increment M(0,0) by one.
   +0 .Move to M(1,0).
   p  .Print its ascii value (32==space).
   +6+5+4+3+2+1+0 .Go back to M(0,0).
)     .When M(0,0)==0 ends the cycle.

Without comments:


Sum Of Two Numbers

*6   .Puts 2^6=64 in M(0,0).
/    .Use the column position register.
+0   .Increment it by 2^0=1.
*5*1 .Puts 2^5+2^1=32+2=34 in M(0,1).

     .Now we add 127 to the row position register to make it go back from 1 to 0.
     .This happens because 1+127=128 but the overflow makes it 0.


     .At this point we are operating again on M(0,0) then.
     .The next instruction increments the next cell of the
      matrix, which is M(0,1) by the value contained in M(0,0).

>0   .Now we move to M(0,1) and print its value.

+0p  .The letter b is printed, because it's ascii value is 64+34=98.

Without comments:


External resources