i32.extend16_s
Pops an i32 value off the stack, only looks at the first 16 bits, converts it into an i32 value, and then pushes it back on to the stack. This only looks at the first 16 bits of the 32 bit integer. The other 16 bits are lost. The 16th bit is used as a sign flag, therefore it is treated as a signed 16 bit number.

Syntax

i32.extend16_s

Stack In

i32 The value to be converted.

Stack Out

i32 The i32 version of the first 16 bits of the i32 value.

Examples

;; Convert i32 0b00000000_00000001 (1) into an i32 value
i32.const 1
i32.extend16_s

;; The stack contains an i32 value of 0b00000001
;; Convert i32 0xAB124129 into an i32 value
i32.const 0xAB124129
i32.extend16_s

;; The stack contains an i32 value of 0x00004129
;; Convert i32 0xAB12F129 (0xF129 = -3799 as signed 16 bit) into
;; an i32 value
i32.const 0xAB12F129
i32.extend16_s

;; The stack contains an i32 value of 0xFFFFF129 (-3799 as signed
;; 32 bit integer)