4 ms·
How to convert an integer to hex digit in 5 bytes: ; AL in range 0..35 (usually 0..15) cmp al,10 sbb al,0x69 das ; AL = '0'..'9', 'A'..
by rep_lodsb 4y ago
How to convert an integer to hex digit in 5 bytes:
; AL in range 0..35 (usually 0..15)
cmp al,10
sbb al,0x69
das
; AL = '0'..'9', 'A'..'Z'
(equivalent code also works on the Z80. Maybe also with the 6502's decimal mode?)
The oldest and least used feature is probably the parity flag. It originally came from the Datapoint 2200 terminal, and still exists even in 64-bit mode!
- krallja 4y ago6502 decimal mode is a flag that changes the behavior of arithmetic operations; there’s no easy way to convert BCD<->binary
- rep_lodsb 4y agoBut the way it changes ALU operation is similar in effect to doing "DAS" after subtraction (it doesn't "convert" to BCD, only adjusts the result). There may be differences in how invalid BCD values are handled though.
- userbinator 4y agoYes, the classic "cmp sbb das". It's well-known amongst the Asm/demoscene community. The opposite, ASCII to nybble in 4 bytes, is a little less well-known: ; AL = 30..39, 41..46, 61..66 and al, 4fh aam 37h ; AL = 0..F It's case-insensitive too.