Binary coded decimal: Difference between revisions
Content added Content deleted
(Added PL/M) |
(→{{header|PL/M}}: Added simple example that is as per the task.) |
||
Line 453: | Line 453: | ||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator) |
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator) |
||
The 8080 PL/M compiler supports packed BCD by wrapping the 8080/Z80 DAA instruction |
The 8080 PL/M compiler supports packed BCD by wrapping the 8080/Z80 DAA instruction with the DEC built in function, demonstrated here. Unfortunately, I couldn't get the first use of DEC to yeild the correct result without first doing a shift operation. Not sure if this is a bug in the program, the compiler or the 8080 emulator or that I'm misunderstanding something... |
||
This is basically {{Trans|Z80_Assembly}} |
|||
<lang pli>100H: /* DEMONSTRATE PL/M'S BCD HANDLING */ |
|||
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */ |
|||
DECLARE FN BYTE, ARG ADDRESS; |
|||
GOTO 5; |
|||
END BDOS; |
|||
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END; |
|||
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END; |
|||
PR$BCD: PROCEDURE( V ); /* PRINT A 2-DIGIT BCD NUMBER */ |
|||
DECLARE V BYTE; |
|||
DECLARE D BYTE; |
|||
D = SHR( V AND 0F0H, 4 ); |
|||
CALL PR$CHAR( D + '0' ); |
|||
D = V AND 0FH; |
|||
CALL PR$CHAR( D + '0' ); |
|||
END PR$BCD ; |
|||
DECLARE ( A, B, I ) BYTE; |
|||
A = SHL( 1, 4 ); /* WORKS AROUND A POSSIBLE BUG IN THE 8080 EMULATOR */ |
|||
/* OR MY UNDERSTANDING OF THE DEC() FUNCTION... */ |
|||
A = 19H; |
|||
CALL PR$BCD( DEC( A + 1 ) ); CALL PR$NL; |
|||
A = 30H; |
|||
CALL PR$BCD( DEC( A - 1 ) ); CALL PR$NL; |
|||
B = 00H; |
|||
A = 99H; |
|||
A = DEC( A + 1 ); /* ADD 1 TO 99 - THIS WILL SET CARRY */ |
|||
B = DEC( B PLUS 0 ); /* ADD THE CARRY TO GET THE LEADING DIGITS */ |
|||
CALL PR$BCD( B ); CALL PR$BCD( A ); CALL PR$NL; |
|||
EOF</lang> |
|||
{{out}} |
|||
<pre> |
|||
20 |
|||
29 |
|||
0100 |
|||
</pre> |
|||
A more complex example, showing how the DEC function can be used to perform unsigned BCD addition and subtraction on arbitrary length BCD numbers. |
|||
<lang pli>100H: /* DEMONSTRATE PL/M'S BCD HANDLING */ |
<lang pli>100H: /* DEMONSTRATE PL/M'S BCD HANDLING */ |
||