Quick and dirty but:
---------------------
Code:
mov eax, op2
add op1, eax
Is always going to be faster than:
-------------------------------------
Code:
mov ebx, opcode_jmp_table_base
vm_loop:
call do_other_vm_stuff
; fetch an opcode and emulate it
mov eax, [opcode_pointer]
lea edx, [ebx + 4*eax] ; load opcode dword jump address for opcode index in eax from jmp table
jmp [edx]
...
...
...
; opcode add a,
OP_ADD:
mov eax, [a] ; fetch a
add eax, [b] ; add b to a
mov [a], eax
inc opcode_pointer
jmp vm_loop
; opcode sub a, b
...
...
...
; more opcodes and cache killing stuff blah blah blah
opcode_jmp_table_base
...
...
...
.dd OP_THIS
.dd OP_THAT
.dd OP_ADD
.dd OP_SUB
.dd OP_MORE
...
...
Not to mention the memory bloat and subsequent I/O penalties for having to load a 8 trillion gigabyte vm executable file for calc.exe.
Hello World in C on a Windows PC is a 12k PE with the bare minimum 3 sections with 4k alignment and 99% of it zero padded. Maybe 2 pages, don't recall what the minimum page count is for a still compliant and valid PE that will load.
Hello World on an Android is what a 30 MB .apk? Seriously? I can get on my NES, initialize all the hardware, procedurally create alpha numeric font tiles for a graphics chip that doesn't have a native text mode, and display Hello World in probably < 1 KB. Why does Android/Java use 30 MB?
Evils like Java are the reason we have web browsers that require 64 GB of RAM to go to
www.google.com and why a simple device like an alarm clock needs 2 GB RAM and a 4 core ARM to tell time we did just fine in 1980 on a 6502 or Z80 with 128 bytes.
I'm not saying enterprise applications should be written in assembly but JFC what's up with the memory footprint of mobile apps and browsers and well just everything lately? And related I hate the file formats where these applications have a million files and sub directories with all these 1k files, because random access storage I/O hasn't already been the Achilles heal of computing for oh the last 3 decades.
Applications like Chrome and Lotus Notes and VM based operating systems like Android are prime examples of RAM and file bloat.