SA
Skip to main content

How is WebAssembly cross-platform when Assembly is not

  • WebAssembly is like Assembly, except that
    • it runs cross-platform
    • it runs isolated
    • it runs on browsers
  • But how is WASM fast and cross-platform simultaneously?
    • Does it pack multiple precompiled binary executables for multiple CPU vendors, like Apple's Universal Binary?
    • But then, whenever a new type of CPU gets announced, they wouldn't be able to run existing WASMs
  • WebAssembly's runtime environments (RE) are low-level virtual stack machines (akin to JVM or Flash VM)
  • Seems like WASM is closer to intermediate Java Byte Code instead of the genuinely low-level Assembly.
    • But then, why is it faster?
    • JS Interpreter can skip the parsing
    • It can ship in a much more compact file format
  • WASM is just like Java Byte-code. Java Byte-code is cross-platform when machine code for a real CPU is not. It's input for a JIT compiler that targets whatever real CPU. Peter Cordes
  • WASM defines its own _CPU standards and Assembly. WebAssembly Core Specification.
  • To run WASM, the browser must still compile the WASM code into ASM code when executing; in that way, it is much slower than WASM.
  • However, WASM is designed similarly to ASM. Therefore, compiling WASM to ASM targeting x86, ARM, and RISC-V, is comparably easy, and existing compilers emitting ASM can also emit WASM with a reasonable modification.
  • What is the relationship between WebAssembly and Assembly?
  • It is a specific purpose Assembly.
  • It's designed with a specific abstract machine that would be expensive to implement in hardware.

References

  1. WebAssembly
  2. How is WebAssembly cross-platform when Assembly is not? - Stack Overflow