CONVERT
Set the left register to the value of the right register with a different size.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $48 | 3 | 3 | convert b:_, p:_ | convert b:1, p:2 |
| $49 | 3 | 3 | convert b:_, i:_ | convert b:1, i:4 |
| $4a | 3 | 3 | convert unsigned p:_, b:_ | convert unsigned p:2, b:4 |
| $4b | 3 | 3 | convert signed p:_, b:_ | convert signed p:2, b:4 |
| $4c | 3 | 3 | convert p:_, i:_ | convert p:2, i:4 |
| $4d | 3 | 3 | convert unsigned i:_, b:_ | convert unsigned i:4, b:8 |
| $4e | 3 | 3 | convert signed i:_, b:_ | convert signed i:4, b:8 |
| $4f | 3 | 3 | convert unsigned i:_, p:_ | convert unsigned i:4, p:8 |
| $50 | 3 | 3 | convert signed i:_, p:_ | convert signed i:4, p:8 |
| Condition flag | Output |
|---|---|
| zero (ZF) | If the result is zero, this flag is 1; otherwise it is 0. |
| negative (NF) | If the signed result is a negative number, this flag is 1; otherwise it is 0. |
| overflow (OF) | If the result exceeds the target register's signed range, this flag is 1; otherwise it is 0. |
| carry (CF) | If the result exceeds the target register's unsigned range, this flag is 1; otherwise it is 0. |
Notes
-
For narrowing conversions (for example,
convert b:1, p:2), you can usefail if overflowto trap overflows. -
The carry (CF) and overflow (OF) flags will always be
0for widening conversions. -
For widening conversions (for example,
convert p:2, sbyte b:4), you must include a type specifier such asbyteorsbyteto indicate whether the value is unsigned or signed. For example, if$femeans -2, then itspairvalue should be$fffe. Whereas if$femeans 254, then itspairvalue should be$00fe.