Please read this page from the main YASEP interface
version 2012-10-04

EZH : Extract and Zero-extend Half-word

This instruction selects a half-word (16 bits that represent a number between 0 and 65535) from the source register, and puts it in the least significant bits of the destination register. The most significant bits of the destination are cleared (set to 0) so the result is a 32-bit unsigned word. It is a kind of equivalent of the SHR opcode but EZH works with a byte granularity, not with bits, as shown on the following diagram:

This instruction is typically used when reading an unsigned halfword from memory to a register, because ESH performs both alignment and zero-padding in a single cycle. However memory is still accessed normally through registers, one word at a time, the IE group of instructions only adjusts the word's contents.

Usually, the halfwords come from a D register (that contains data coming from memory) and the index of the first byte inside this word is provided by a A register, but any register can be used. The index can also come from immediate data (Imm4 ou Imm16), which explains why the index is always written first in the instruction.

; Load 16 bits from memory at address 321h into register R1 :
MOV 321h A1
EZH A1 D1 R1

Currently, this opcode is only assembled with the iRR and RRR forms, even though other forms are possible.

This instruction handles 16-bits words but the YASEP32's pointer have byte granularity, so unaligned half-words are possible. However, not all alignments can be adjusted by this instruction: if the two LSB of the index contain 11 then the Carry is set to indicate that more code is necessary to load the next byte of the next word. The Most Significant Bits are cleared, which eases the combination of the data with other instructions such as OR or IB:

; load 16 bits from memory at address 123h into register R1 :
MOV 123h A1  ; the 2 LSB of this address are set to 1
EZH A1 D1 R1 ; which sets the carry bit to 1 
; Get the next byte from the next word :
ADD 1 A1      CARRY ; point to the next word
IB 1 D1 R1    CARRY ; insert the new byte in second position

EZB is similar but works on unsigned bytes.

ESH is similar but works on signed half-words (and out-of-word alignment requires more instructions).