Getting Physical with Developmental Biology Research

While genetics and biochemistry research has dominated the conversation about how human bodies are formed, new research — with an old twist — is proposing that there is another star in the show of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Understanding WebAssembly Architecture

Programming WebAssembly with Rust — by Kevin Hoffman (12 / 71)

👈 Introducing WebAssembly | TOC | Building a WebAssembly Application 👉

In this section, you’ll get a good look inside the engine that makes WebAssembly work. Its unique architecture makes it incredibly powerful, portable, and efficient — though this power comes with some limitations.

The type of computer that you’re using right now is likely a Register Machine. Laptops, desktops, mobile devices, virtual machines, even microcontrollers and embedded devices are register machines. A register machine is a machine (physical or virtual) where the processor instructions explicitly refer to certain registers, or data storage locations, on the processor. Accessing these registers is fast and efficient because the data is available directly within the CPU.

For example, if you want to add two numbers together, you’d use the ADD instruction and you’d pass it the names of two registers as parameters, as shown in this bit of x86 assembly:

In the preceding code, the values contained in ah and al will be added together, with the result stored in al.

WebAssembly is a stack machine. In a stack machine, most of the instructions assume that the operands are sitting on the stack, rather than stored in specified registers. The WebAssembly stack is a LIFO (Last In, First Out) stack. If you’re unfamiliar with the concept of a stack: it is as its name implies — values are piled (stacked) on top of each other, and unlike arrays where you can access any data regardless of location in the pile, stacks only allow you to pop data off or push data onto the top.

To add two numbers in a stack machine, you push those numbers onto the top of the stack. Then you push the ADD instruction onto the stack. The two operands and the instruction are then popped off the top and the result of the addition is pushed on in their place.

There are a number of advantages to a stack machine that made it an appealing choice for WebAssembly: their small binary size, efficient instruction coding, and ease of portability just to name a few.

There are some fairly well-known stack machines, including the Java Virtual Machine (JVM) and the bytecode executor for the .NET Common Language…

Add a comment

Related posts:

How to Cause Diffusion

You now have an overview of how to build Brownian motion, Geometric Brownian motion, and Jump Diffusion. This section will show you how to get random numbers for the stochastic part of the…

Chapter 8 Working with Files

All the programs you’ve worked with so far have taken input from the end user or used hard-coded values. But many programs use files to store data. Your operating system and its programs write logs…