[LWN Logo]
[LWN.net]
From:	 "Rick A. Hohensee" <rickh@Capaccess.org>
To:	 konst@linuxassembly.org
Subject: osimpa blurb
Date:	 Fri, 07 Dec 2001 18:22:15 -0500
Cc:	 fare@tunes.org, lwn@lwn.net, linux-assembly@vger.kernel.org

----=_--b836b968.01990738.000003b5

I'm writing a text editor in osimpa, and I'm trying some things the hard
way on top of that, and it's eating my head. BUT, osimpa itself isn't much
of the problem anymore, other than slowness, i.e. it's getting useable.
Hmmmm. Time to take a step back and crow a bit. Have a blurb.



osimpa is a macro-assembler or "compembler" written entirely in GNU Bash.
With minor modifications it should also work with pdksh and zsh. It
currently supports the Intel 80386 real and protected modes. No floats,
etc.. The osimpa script is currently 116k including a lot of
per-instruction help prompt texts. The "compembler" thing is about being
as convenient as possible without creating restrictions to low-level
access. This results in some degenerate imitations of high-level language
features that lose some generality but that win huge on bang-per-buck in
terms of implementation complexity.

osimpa emphasizes some of the same things as Forth, but without a Forth
(virtual) 2-stack-machine; a consistant simple syntax (no lexer), terse
but self-explanatory names, ease of extension, systemic simplicity, and
minimal external dependancies. Structured programming, object oriented
programming, functional programming and data typing are not directly
supported. Although not typed in the C sense, data is sized somewhat by a
cell concept. There's a lot of defaulting of things for the common case,
and cells default to 4 bytes. Composites that assemble more than one
instruction are provided for the 386 prefixed looping instructions,
execution arrays, host system calls, reentrant procedures, and a register
dump. Other conveniences resemble Forth ALLOT, C enum, C struct, Forth
VARIABLE, Forth CR, C printf, and some handy features the 386 doesn't have
like a 0 register. The "heap" word allows unallocated memory in the
storage image of the program. The "when" construct for conditional
branches and osimpa strand arrays are fairly unique. osimpa code doesn't
look very CPU-specific, and I believe it could be generalized to port
easily between most desktop one-stack CPUs.

osimpa in Bash is very slow, but very interactive otherwise, and the
produced code is as good as you are. Listed below is a playful little
Linux command in osimpa. The = A to B (Intel MOV ebx,eax) instruction is
gratuitous. Such a simple program as this didn't need any non-composite
instructions, so I just stuck one in to show that there is no syntactic
or semantic hurdle between composites and per-instruction assembly.
Similarly, ab assembles specific bytes without any conflict with more
complex actions. obverse and reverse are vt102 display directives
supported by the Linux console driver.

ELF
        = A to B
        Linux $write 0 $reverse 4
        print hiya   ; Linux $write 0 $obverse 5
        print hiya                                      # comment
        print hiya
        Linux $exit
L reverse
        ab 0x1b `asciibyte [ 7 m`
L obverse
        ab 0x1b `asciibyte [ 2 7 m`
text hiya <<!

Good morning Mister Felps. Your mission, should you choose to accept
it...
.
 .
 .
!

Where possible, implementation is kept simple and the learning curve is
kept shallow by reusing the functionality of the shell. The osimpa "text"
directive uses a shell here-document, for example. The above osimpa source
is a shell script that creates a stand-alone executable. ELF, =, Linux,
print, L and text are shell "functions".

Here's the osimpa compembly-time listing of the above. 3-digit numbers in
the second column are octal.

7f E  L  F  01 01 01 00 00  o  s  i  m  p  a 0a
02 00 03 00 01 00 00 00 54 00 00 00 34 00 00 00
00 00 00 00 00 00 00 00 34 00 20 00 01 00 28 00
00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00         segment header
30 01 00 00 30 01 00 00 07 00 00 00 00 10 00 00

00000054  89 303      = A to B          ##
00000056  270 04 00 00 00           =   4 to A          ##  Linux
0000005b  273 00 00 00 00           = 0 to B            ##  Linux
00000060  271 ce 00 00 00           = 206 to C          ##  Linux
00000065  272 04 00 00 00           = 4 to D            ##  Linux
0000006a  cd 80                     trap 128            ##  Linux
0000006c  8b 025 d7 00 00 00        = @ 215 to D                ##  print
00000072  271 db 00 00 00           = hiya to C         ##  print
00000077  273 01 00 00 00           = 1 to B            ##  print
0000007c  270 04 00 00 00           =   4 to A          ##  Linux  print
00000081  cd 80                     trap 128            ##  Linux  print
00000083  270 04 00 00 00           =   4 to A          ##  Linux
00000088  273 00 00 00 00           = 0 to B            ##  Linux
0000008d  271 d2 00 00 00           = 210 to C          ##  Linux
00000092  272 05 00 00 00           = 5 to D            ##  Linux
00000097  cd 80                     trap 128            ##  Linux
00000099  8b 025 d7 00 00 00        = @ 215 to D                ##  print
0000009f  271 db 00 00 00           = hiya to C         ##  print
000000a4  273 01 00 00 00           = 1 to B            ##  print
000000a9  270 04 00 00 00           =   4 to A          ##  Linux  print
000000ae  cd 80                     trap 128            ##  Linux  print
000000b0  8b 025 d7 00 00 00        = @ 215 to D                ##  print
000000b6  271 db 00 00 00           = hiya to C         ##  print
000000bb  273 01 00 00 00           = 1 to B            ##  print
000000c0  270 04 00 00 00           =   4 to A          ##  Linux  print
000000c5  cd 80                     trap 128            ##  Linux  print
000000c7  270 01 00 00 00           =  1 to A           ##  Linux
000000cc  cd 80                     trap 128            ##  Linux
000000ce                (O) reverse1b 5b 37 6d
000000d2                (O) obverse1b 5b 32 37 6d
000000d7  55 00 00 00           TEXT length
000000db                (O) hiya

Good morning Mister Felps. Your mission, should you choose to accept
it...
.
 .
 .


osimpa is in
                ftp://linux01.gwdg.de/pub/cLIeNUX/interim
but my
net.presence is in bad shape, and osimpa is still changing frequently, so
email me for the latest.  As of Dec. 2001 osimpa is public domain. Later
versions may be encumbered with cLIeNUX. Please feel free to proliferate
this blurb.

Rick Hohensee
rickh@capaccess.org