官术网_书友最值得收藏!

A brief introduction to WebAssembly text

WebAssembly binary is not a language, but a build target similar to building for ARM or x86. The bytecode, however, is structured differently than other hardware-specific build targets. The designers of the WebAssembly bytecode had the web in mind. The aim was to create a bytecode that was compact and streamable. Another goal was that the user should be able to do a "view/source" on the WebAssembly binary to see what is going on. WebAssembly text is a companion code to the WebAssembly binary that allows the user to view the bytecode instructions in a human-readable form, similar to the way an assembly language would let you see what opcodes execute in a machine-readable form.

WebAssembly text may initially look unfamiliar to someone used to writing assembly for hardware such as ARM, x86, or 6502 (if you're old school). You write WebAssembly text in S-expressions, which has a parentheses-heavy tree structure. Some of the operations are also strikingly high level for an assembly language, such as if/else and loop opcodes. That makes a lot more sense if you remember that WebAssembly was not designed to run directly on computer hardware, but to download and translate into machine code quickly.

Another thing that will seem a little alien at first when you are dealing with WebAssembly text is the lack of registers. WebAssembly is designed to be a virtual stack machine, which is an alternative to a register machine, such as x86 and ARM, with which you might be familiar. A stack machine has the advantage of producing significantly smaller bytecode than a register machine, which is one good reason to choose a stack machine for WebAssembly. Instead of using a series of registers to store and manipulate numbers, every opcode in a stack machine pushes values on or off a stack (and sometimes does both). For example, a call to i32.add in WebAssembly pulls two 32-bit integers off the stack, adds them together, then pushes their value back on to the stack. The computer hardware can make the best use of whichever registers are available to perform this operation.

主站蜘蛛池模板: 桓仁| 黑龙江省| 上蔡县| 泰兴市| 布尔津县| 米脂县| 屏山县| 乌拉特中旗| 石柱| 乳山市| 宜宾县| 宁德市| 龙江县| 裕民县| 樟树市| 敖汉旗| 恭城| 正阳县| 定南县| 府谷县| 油尖旺区| 顺义区| 阿坝县| 榆树市| 星子县| 宜都市| 姜堰市| 禄丰县| 宁海县| 济宁市| 黑河市| 重庆市| 浮山县| 黑河市| 平罗县| 辽宁省| 资溪县| 东平县| 云安县| 龙南县| 柘荣县|