flat assembler
Message board for the users of flat assembler.

 flat assembler > Programming Language Design > Challenger Interpreter Goto page Previous  1, 2, 3  Next
Author
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
Some graphical demo:
Code:
```v_EEE@^EEE^@WUU]@_BDB_
>v    >:>2\?!%#v_" \.>2\?/#v_v
v \0.<5 !      >"#\. ^     v "
>,=)^) ^                  <
>="0: ^> (.1+\        v      \
= ?!|                     >
^      x#             <    ```
31 Aug 2009, 16:01
windwakr

Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
AWESOME!
31 Aug 2009, 16:17
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
Another example, this time some arithmetic one, as a proof of assembly-like style of this language.
It goes to the fifth row (it is defined by constant in the first character of program), looks for decimal value there and converts this string into value in accumulator. Then it calculates the square of this number, and writes it back as a decimal string in the row below the original number:
Code:
```)5:(["0!>0+&-&`#v_0!>A&*.-&+!.0+v
^      .<   ^           _v
v0"\%\A&!&+0<[,]\*&!?<
>+!.A\/\0+ #^_x

1234    ```
This is the first time I used the & instruction, and I used it extensively.
02 Sep 2009, 21:29
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
After this post you may conclude I am completely out of my mind. ;)
I've written a simple Brainfuck interpreter in Challenger.

There are three special rows on program's plane, marked with "PROGRAM:", "INPUT:" and "OUTPUT:" texts. After the "PROGRAM:" you should put the program to be interpreted and after the "INPUT:" sequence of bytes that will be fed into program when it requests input.
The row following the "OUTPUT:" text will be filled with output generated by program. The row just below program is used for the program's data storage.

I included the windwakr's 66-char solution to challenge 1 in from the Esoteric Programming Challenges! thread. Note that the newline character (and other control characters) is written into output just as any other character in this implementation. Well, it's a specific one.
Code:
```v        v\+.(=1  <
> =0"0.-)v
#
INPUT:
#
>              ^
v        \ ":(..<

PROGRAM:++++++++++[>+>++++++<<-]++[>>>>+++++[<<+>+++++>-]<+[<.+>-]<+<.<-],
=
>            @v
]     v ],,[<                                    >&?                v
!          >v   >v   >v   >v   >v   >v   >v   >0+|
( >   >&",-|>".-|>">-|>"<-|>"+-|>"--|>"[-|>"]-|  x
A^       ?&<
:  v +0):)=6  ?&<
0  .v\+1:)=7       ?&<                             v          <  &\<
+  : v\1:)=8            ?&<                        .      >"[-|
.  0 -v):)=9                 ?&<          >.1\]],,&>   "]-|   >&1\-|
:  + \>0+.:1+ >]!"@\4*&\%&\?[    v        )        ^.&\+1&<        ]
?     v):)=B                      ?&<     =                        ]
[     >0+.:1\-^>                          ^
\     v):)=D                           ?&<
>0+.:0+    v                             v          <  &\<
v):)=F                                ?&<.      >"]-|
>0+.:0+  |v_=).1\                       &>   "[-|   >&1\-|
> ^ <<         <<                <            <^.&\+1&<        \
^               ,<   <
v\+.(=1  <                             ^                     <
> =0"0.-)v
#
OUTPUT:
#
>      =).\  ^
^      \ ":(..<    ```

PS. Don't worry. I'm going to get back to fasm development soon.

Last edited by Tomasz Grysztar on 03 Sep 2009, 14:54; edited 1 time in total
03 Sep 2009, 13:29
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 16631
Location: In your JS exploiting you and your system
Tomasz Grysztar wrote:
After this post you may conclude I am completely out of my mind.
Well ...
Tomasz Grysztar wrote:
I've written a simple Brainfuck interpreter in Challenger.
... if you write a befunge interpreter then I might think that.

BTW: Challenger has no random number generator instruction and no external input, so I don' think you can emulate befunge properly.
03 Sep 2009, 13:36
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
revolution wrote:
BTW: Challenger has no random number generator instruction and no external input, so I don' think you can emulate befunge properly.
Well, one would have to implement PRG subroutine, as for the input/output - the same problem as with above interpreter.
However, if I add ability to poke values by user at the runtime in the Challenger's plane, it might be possible to write some routines waiting for input in a specific cell (just like you may read a keyboard port in a loop with assembly language).

Anyway, you're right, I'm not that completely out of my mind, trying to implement Befunge is not in my scope.
03 Sep 2009, 13:42
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 16631
Location: In your JS exploiting you and your system
If someone writes a befunge interpreter in Brainfuck (albeit without the PRNG) then Challenger will also have a befunge interpreter. An interpreter (Challenger) emulating and interpreter (brainfuck) for an interpreter (befunge). Now if you run all that inside a VM on a PC that has a hypervisor ... ooh, my head hurts.
03 Sep 2009, 13:56
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
BTW, I think I've chosen the wrong approach for this interpreter - I used SP to point into current position in program; if I used it to point to program's data instead, then the data range would be theoretically unlimited (and perhaps the interpreter implementation would become a bit simpler, too). Currently range of data is limited by the maximum size of offset stored in one cell. Of course, this is only theoretical thing, because in practice the plane is even more limited by the 32-bit assembly implementation of Challenger Interpreter.
03 Sep 2009, 14:08
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
One more thing (this is the last one, I promise ;)). This time purely theoretical, thus perhaps even less interesting that previous ones.
In order to prove the Turing completeness of Pure Challenger, I made an implementation of 2-state 5-symbol universal Turing machine.
The machine itself is implemented in lines starting from sixth, the initial code just sets up the pointer on the tape in the third row - the small patch of tape is pre-initialized for testing rule 101 emulation (of course for the real thing the whole infinite tape would have to appropriately initialized). The values are processed modulo 5, and because value of capital A is 65, the range of letters A-E is ideal for this purpose.
Code:
```v
#
BBBBBBBBBBBBBAEAAAAAAAAAAAAAAA
>:F:).v
v((.<
>"D\(.)v
>3-|
>2-|  >"E\).(v
>\1-|  >"A\).(v
>5\%|   >"A\).(   v
>"B\(.)       v
^                 <
>                     v
^ ).(\C"<
|-3<
^ (.)\E"<  |-2<
^   (.)\E"<  |-1\<
^      (.)\A"<   |%\5<
^          ).(\D"<    ```

Last edited by Tomasz Grysztar on 03 Sep 2009, 18:20; edited 1 time in total
03 Sep 2009, 18:12
MazeGen

Joined: 06 Oct 2003
Posts: 953
Location: Czechoslovakia
Tomasz Grysztar wrote:
PS. Don't worry. I'm going to get back to fasm development soon.

Haha, that was exactly the first idea which came to my mind while reading this thread today.
03 Sep 2009, 18:19
r22

Joined: 27 Dec 2004
Posts: 805
This could be the new MACRO language for FASM 2.x
I'm uncertain whether this would make macro writing in FASM easier or more difficult
03 Sep 2009, 18:34
rugxulo

Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
MazeGen wrote:
Tomasz Grysztar wrote:
PS. Don't worry. I'm going to get back to fasm development soon.

Haha, that was exactly the first idea which came to my mind while reading this thread today.

Really? 'Cause I can't think of any high-priority in FASM development that would supercede such a fun distraction as this.

EDIT: More proof that Tomasz really is an "artist" !!
03 Sep 2009, 22:18
Pinecone_

Joined: 28 Apr 2008
Posts: 180
I hope you don't mind Tomasz, I added your brainfuck interpreter to the Esoteric Programming Challenges! thread under challenge 5 (write a brainfuck interpreter). You are now the only person who's done that challenge (I'm going to try it soon though, in befunge [after I update my interpreter to handle befunge-98 code {which could be quite a while...}])
04 Sep 2009, 15:39
windwakr

Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
You(or someone else) should create a page for it on the Esolangs wiki to get more interest in it.

_________________
----> * <---- My star, won HERE
06 Sep 2009, 18:55
neville

Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
A modified graphical demo
Code:
```v_EEE@^EEE^@_BDB_@NQQQN@VUUM
>v    >:>2\?!%#v_" \.>2\?/#v_v
v \0.<5 !      >"@\. ^     v "
>,=)^) ^                  <
>="0: ^> (.1+\        v      \
= ?!|                     >
^      x#             <    ```

Note: ".chl" attachments are not allowed in this forum

_________________
FAMOS - the first memory operating system
06 Sep 2009, 22:02
neville

Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
A slightly optimised version of Tomasz's Framed Chalenger string copy program (40 bytes, was 46):
Code:
```)3:(]2;[>?\"!-v
^_x#. <
Hello!    ```

A more optimised version (32 bytes) but the string is limited to 8 chars including delimiter (or excluding delimiter if ^ used!):
Code:
```)4:(]1;[>?\".-v
hello  .^_x#. <    ```

And now the Windoze (bloatware) version - 4 times bigger and runs at 1/4 speed with some unnecessary flashy stuff :lol:
(Best viewed at 8 Hz):
Code:
```)3:(]2;[>?\"!-([([([([])])])])(((([[[[(((())))]]]]))))[][][][]()()()()[]()v
^_x#. [[[[[[[[[[[[((((((((((((]]]]]]]]]]]]))))))))))))[[[[[[[[[[[[<
Hello!    ```

Replace :( with colon( as required! BBCode disabled - that removed the code boxes and left the smilies (geez, rev :) Smilies disabled - did the trick!

_________________
FAMOS - the first memory operating system

Last edited by neville on 07 Sep 2009, 11:51; edited 2 times in total
07 Sep 2009, 10:46
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 16631
Location: In your JS exploiting you and your system
neville: tick the box in the edit window to disable BBCode in your post.

 Oops, yeah, disable the smileys, I knew it was one of those option thingies.
07 Sep 2009, 10:50
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
I uploaded the version 1.0 of interpreter. It finally has the option to manipulate the plane contents in real time. With Peek command you can read the value of a cell (you have to click the cell with mouse), and with Poke you can write the value to any cell (who does know where I took those names from? ).

With the existence of Poke command it's now possible to emulate a real-time input for the Challenger programs. Here is an example:
Code:
```]5;]v
>  0=).\#v_
!IN:
^        <    ```

It repeatedly reads the cell that comes just after the "IN:" text, and if it detect any non-zero value there, it writes it out in the row below the program. It is quite similar to program that would continuously read the keyboard port to detect the user input. I suggest to run it at maximum speed and drop a few characters with Poke command into a cell after "IN:" to see the effect.

I wonder if you could make some kind of game this way.
08 Sep 2009, 14:56
neville

Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
Tomasz Grysztar wrote:
I uploaded the version 1.0 of interpreter. It finally has the option to manipulate the plane contents in real time. With Peek command you can read the value of a cell (you have to click the cell with mouse), and with Poke you can write the value to any cell (who does know where I took those names from? ).
Over 30 years ago I wrote a crude Z80 editor/assembler in BASIC using PEEK & POKE commands on my TRS80 clone (with 16Kb RAM, expanded to 48Kb by piggy-backing the RAM chips 3 high)

With the Poke command it not only provides real-time input but it's also possible to change the program code while the program is running. Nice! (best done at 8Hz!) In fact you could even write a program from scratch while it is running, so it executes code as you enter it. This could be the genesis of a Challenger game, where the IP follows you around.... Then when you can do it at 8Hz, try 50Hz! Maybe not maximum speed though

_________________
FAMOS - the first memory operating system
08 Sep 2009, 21:07
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7289
Location: Kraków, Poland
neville wrote:
A slightly optimised version of Tomasz's Framed Chalenger string copy program (40 bytes, was 46):
Code:
```)3:(]2;[>?\"!-v
^_x#. <
Hello!    ```

I made a definitely smaller version, which copies the null-terminated string (and since Challenger plane is filled with zeros by default, it copies everything that you write in the second line):
Code:
```],[)2:(> #.?#\_x
Hello!    ```
09 Sep 2009, 10:44
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area
Goto page Previous  1, 2, 3  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum