A.ANATOLICACONSULTING, LLC

EFOS Playground

Write a small program, run it on EFVM, the virtual processor of EFOS, and watch registers, memory and output change one instruction at a time. Write EFASM assembly directly, or write efclang, the EFOS Easy & Flexible language, and see the assembly it becomes.

How to use this playground about a minute to read

Get going

  1. Pick a sample from the menu, or type your own program in the editor.
  2. Press Run to execute it. Text the program prints appears in Console output.
  3. Press Step to run one instruction at a time. The yellow line in the editor is the instruction about to run. Step back undoes one step.
  4. Click a row in Code to set a breakpoint (a red dot). Run stops there.
  5. Press Reset to start the program again from the top.

What you are looking at

  • Registers R0 to R7 are the CPU's eight 32-bit variables. R7 is the stack pointer. A register that just changed is highlighted.
  • ZF / NF are flags set by CMP: zero and negative. Branches like BEQ and BLT read them.
  • Memory shows the program's bytes. Strings you define with DZ start at address 0. Use Data and Stack to jump around.
  • Your edits are saved in this browser only. Share copies a link that holds your program inside the link itself, so anyone who opens it sees the same code. Nothing is stored on any server.

Things to try

  • New: press efclang above, open fizzbuzz and Run. Then open Show the assembly this program became and Step through it.
  • Open countdown, change #5 to #9, and Run.
  • Step through it and watch R1 fall while the flags change at each CMP.
  • Open hello, then edit the text in the quotes.
  • In fib, change #12 to print more numbers.
  • Write your own: add the numbers 1 to 10 and print the sum.
  • Make a mistake on purpose. The assembler names the line and column.

Write in efclang

  1. Pick a sample from the menu: hello is the shortest, fizzbuzz and primes use loops and functions.
  2. Press Run. The page turns your program into machine code and runs it. What it prints appears in Console output.
  3. Edit the program and press Run again. A mistake is reported with its line and column.
  4. Open Show the assembly this program became under the editor to read the machine code the compiler wrote.
  5. Step runs one machine instruction at a time and highlights the line of your program it belongs to.

Things to try

  • In fizzbuzz, change 20 to 40 and Run.
  • In primes, change 100 to 300.
  • In fib, Step into a call and watch R7 (the stack pointer) fall in the Machine panel.
  • Replace the program with this one and Run: fn main() { var s = 0; for (var i = 1; i <= 10; i += 1) { s += i; } print(s); return 0; }
  • Pick mandelbrot (picture) or circles (picture) and Run: a Screen panel appears below the console. In lines (picture), change colour(i) and watch the fan change.
  • Pick paint (interactive) or snake (interactive), press Run, then click the picture and use the mouse or the arrow keys.
  • Draw your own: fn main() { screen(32, 32); drawline(0, 0, 31, 31, 0xFF0000); return 0; }
  • Make a mistake on purpose, such as using a name you never declared.
efclang reference the code you write when you choose "efclang"
You writeWhat it means
fn main() { ... return 0; }Every program starts in main. What it returns becomes the exit code.
var x = 5;  |  x = x + 1;  |  x += 1;Variables hold whole numbers (32-bit, can be negative). Declare them with var, inside a function or at the top.
const N = 10;A name for a fixed number, worked out when the program is compiled.
var table[16];  table[i] = 3;An array of 16 numbers, counted from 0. Declared at the top level only. Stay within the size: nothing checks it.
if a < b { ... } else { ... }Choose. No parentheses needed. Compare with == != < <= > >=; combine with && || !.
while cond { ... }  |  for (var i = 0; i < 10; i += 1) { ... }Repeat. break; leaves a loop, continue; skips to the next round.
fn add(a, b) { return a + b; }Your own functions, with any number of inputs. They can call themselves.
+ - * / % & | ^ ~ << >>Arithmetic and bit operations. / and % round toward zero. Numbers can be written 255, 0xFF or 'A'.
print(x)  |  write(x)  |  putc(65)  |  puts("hi\n")Print a number and newline; a number alone; one character; a piece of text.
exit(3);End the program at once with that exit code.
screen(64, 48);Open a drawing screen 64 dots wide and 48 high. Dots are counted from the top-left corner, (0, 0). Everything else needs this first.
cls(0x101820);Fill the whole screen with one colour. Colours are written 0xRRGGBB: red, green, blue, two hex digits each (0xFF0000 is red).
pixel(x, y, colour)  |  drawline(x1, y1, x2, y2, colour)Colour one dot; draw a straight line between two dots.
drawrect(x, y, w, h, colour)  |  fillrect(x, y, w, h, colour)Draw the outline of a box, or a solid box. Parts outside the screen are cut off, not an error.
present();  |  closescreen();Show the finished picture and wait for the next screen refresh (about 60 times a second, so a loop that calls present() once per round runs at a steady speed); close the screen. Each drawing command returns 0 when it worked and a negative number when it did not (for example, no screen yet).
while nextinput() { ... input(0) ... }Read the keyboard and mouse. nextinput() takes the next event (1 if there was one, 0 if not); input(n) then reads its parts: 0 kind (1 key, 2 mouse), 1 action (1 press, 2 release, 3 move, 4 wheel), 2 key or button code, 3 character or wheel step, 4 and 5 mouse x and y, 6 shift/ctrl/alt bits. Letters and digits give their capital letter or digit as the code, Enter 13, Esc 27, arrows 257 to 260.
inputcount()  |  inputinfo(i, n)How many events are waiting; peek at part n of the ith waiting event without taking it.

The CPU can only add, subtract and compare, so the compiler writes extra routines for *, /, % and shifts. Open Show the assembly this program became under the editor to see everything it generated, and use Step to follow it. Limits: the whole program must fit in 2047 instructions and 2 KB of data. Screens up to about 4 million dots work in this page.

Assembly quick reference instructions and system calls
InstructionWhat it does
MOV Rd, #n  |  MOV Rd, RaPut a number, or another register's value, into Rd. A label such as message gives its address.
ADD / SUB Rd, Ra, Rb|#nRd = Ra plus or minus a register or a number.
AND / OR / XOR Rd, Ra, RbBitwise operations on whole registers.
CMP Ra, Rb|#nCompare. Sets the flags; changes no register.
JMP / BEQ / BNE / BLT / BLE / BGT / BGE labelJump to a label: always, or if equal, not equal, less, less or equal, greater, greater or equal (after a CMP).
CALL label  |  RETCall a routine and return from it (uses the stack).
LD / LDB Rd, [Ra] or [Ra+n]Load a 32-bit word, or one byte, from memory.
ST [Rd] or [Rd+n], RbStore a register into memory.
OUT RdPrint a register as a number on its own line.
SYS #nAsk the system to do something (see the calls below).
HALTStop the program.
label:Names this spot. Comments start with ;. Numbers start with # (#10 or #0xFF).
DZ name, "text"  |  DB name, #n, ...Define text (ending in zero) or raw bytes in memory. Escapes: \n \t \" \\ \xNN.
System callInputsWhat it does
SYS #34R0 = numberPrint R0 as a number (no newline).
SYS #35Print a newline.
SYS #2R0 = character codePrint one character.
SYS #4R0 = 1, R1 = addressPrint the zero-ended string at that address.
SYS #1R0 = 1, R1 = address, R2 = lengthPrint that many bytes.
SYS #33 / #37 / #38R0 = size, or addressAllocate, resize and free memory.
SYS #5 / #6R0 = to, R1 = value or from, R2 = lengthFill or copy memory.
SYS #0R0 = exit codeEnd the program.

Program

Console output


    

Machine

Code click a row to set a breakpoint

Memory