JSFiddle - React, Tailwind, and code Playground

by Alexander

JavaScript

console.clear();

const mem = {}
const stack = []
const func = []

window.foo = (a, b) => a + b

const mov = s1 => s2 =>
	mem[s1[0]] = s2[0]

const add = s1 => s2 =>
  mem[s1[0]] = mem[s1[0]]|0 + 0|mem[s2[0]]

const push = s1 =>
	stack.push(mem[s1[0]])

const pop = s1 =>
	mem[s1[0]] = stack.pop()

const xor = s1 => s2 =>
	mem[s1[0]] = (mem[s1[0]]|0) ^ (0|mem[s2[0]])

const call = s1 => {
	func.push(this[s1[0]].call(null, ...stack))
}

const ret = s1 => mem[s1[0]] = func.pop()

const print = s1 => console.log(mem[s1])

// Assembler code

// swap 2 values
mov `eax` `1`
mov `ebx` `2`

xor `eax` `ebx`

push `eax`
push `ebx`

call `foo`
ret  `ecx`

pop   `eax`
pop   `ebx`

print `eax`
print `ebx`
print `ecx`