Define wordΒΆ

The dw keyword compiles to a single field element of data directly in the code. For example:

dw 0x123;

will be translated to the field element 0x123 in the bytecode. This is not really an instruction, and therefore should not be in any execution path. A common use for this is constant arrays:

from starkware.cairo.common.registers import get_label_location

// Returns a pointer to the values: [1, 22, 333, 4444].
func get_data() -> (data: felt*) {
    let (data_address) = get_label_location(data_start);
    return (data=cast(data_address, felt*));

    dw 1;
    dw 22;
    dw 333;
    dw 4444;

func main() {
    let (data) = get_data();
    tempvar value = data[2];
    assert value = 333;
    return ();