You are here

I want split a word variable to two bytes, or into bits, what's the best way to do it in JAL?

A common way to address the individual bytes of a word (or larger)
variable is to split it as an array of bytes.

This can be done as follows

var word w
var byte wb[2] at w

You can then refer the two bytes of the word w as wb[0] and wb[1]

To define bits within a byte, you may do the following:
var byte my_byte
var bit my_bit at my_byte : 0
var bit*3 my_bits at my_byte : 1

If the individual bytes of an array need a specific name alias keyword can be used as given below.

var word val
var byte val_array[2] at val
var byte hibyte at val + 0
var byte lowbyte at val + 1

Here is another example:

var byte*10 val
var byte val_array[10] at val
var byte byte5 at val + 5
var word byte7_8 at val + 7
var volatile bit bit0 at byte5 : 0
var volatile bit*3 bits at byte5 : 1

Don't define a bit*3 variable where it will pass the end of a byte. This will not work:
var bit*3 bits3 at byte5 : 7