Skip to navigation

Revs on the BBC Micro

Maths (Arithmetic): Negate16Bit

Name: Negate16Bit [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Negate a 16-bit number
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyTyreForces calls Negate16Bit * ProcessDrivingKeys (Part 2 of 6) calls Negate16Bit * AssistSteering calls via Negate16Bit+2 * ProcessDrivingKeys (Part 2 of 6) calls via Negate16Bit+2 * SubtractCoords calls via Negate16Bit+2

This routine negates the 16-bit number (A T).
Other entry points: Negate16Bit+2 Set (A T) = -(U T)
.Negate16Bit STA U \ Set (U T) = (A T) LDA #0 \ Set (A T) = 0 - (U T) SEC \ = -(A T) SBC T \ STA T \ starting with the low bytes LDA #0 \ And then the high bytes SBC U RTS \ Return from the subroutine