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 use FAIL IF OVERFLOW to trap overflows. -
The
CARRYandOVERFLOWflags will always be0for 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.