Prev: 346A Up: Map Next: 3492
346E: THE 'UNARY MINUS' OPERATION (offset +1B)
Used by the routine at subtract.
The address of this routine is found in the table of addresses. It is called via the calculator literal +1B by the routines at CD_PRMS1, get_argt, cos, atn, asn and acs. It is also called indirectly via fp_calc_2.
This subroutine performs its unary operation by changing the sign of the 'last value' on the calculator stack.
Zero is simply returned unchanged. Full five byte floating-point numbers have their sign bit manipulated so that it ends up reset (for 'abs') or changed (for 'negate'). 'Small integers' have their sign byte set to zero (for 'abs') or changed (for 'negate').
Input
HL Address of the first byte of the number
Output
negate 346E CALL TEST_ZERO If the number is zero, the subroutine returns leaving 00 00 00 00 00 unchanged.
3471 RET C
3472 LD B,$00 B is set to +00 for 'negate'.
This entry point is used by the routine at abs.
NEG_TEST 3474 LD A,(HL) If the first byte is zero, the jump is made to deal with a 'small integer'.
3475 AND A
3476 JR Z,INT_CASE
3478 INC HL Point to the second byte.
3479 LD A,B Get +FF for 'abs', +00 for 'negate'.
347A AND $80 Now +80 for 'abs', +00 for 'negate'.
347C OR (HL) This sets bit 7 for 'abs', but changes nothing for 'negate'.
347D RLA Now bit 7 is changed, leading to bit 7 of byte 2 reset for 'abs', and simply changed for 'negate'.
347E CCF
347F RRA
3480 LD (HL),A The new second byte is stored.
3481 DEC HL HL points to the first byte again.
3482 RET Finished.
The 'integer case' does a similar operation with the sign byte.
INT_CASE 3483 PUSH DE Save STKEND in DE.
3484 PUSH HL Save pointer to the number in HL.
3485 CALL INT_FETCH Fetch the sign in C, the number in DE.
3488 POP HL Restore the pointer to the number in HL.
3489 LD A,B Get +FF for 'abs', +00 for 'negate'.
348A OR C Now +FF for 'abs', no change for 'negate'.
348B CPL Now +00 for 'abs', and a changed byte for 'negate'; store it in C.
348C LD C,A
348D CALL INT_STORE Store result on the stack.
3490 POP DE Return STKEND to DE.
3491 RET
Prev: 346A Up: Map Next: 3492