![]() ![]() Subtract the smaller absolute value from the larger absolute value.If A and S have different signs, then we can use the absolute values of A and S to work out the sum, as follows:.If both A and S are negative, then add them and make sure the result is negative.If both A and S are positive, just add them as normal.However, if we use the built-in ADC instruction, we get the following: 127 + -1 = 01111111 + 10000001Įlite's ADD routine implements sign-magnitude addition using the following algorithm. This means that when we come to do arithmetic on sign-magnitude numbers, we have to write our own routines for everything from addition and subtraction to multiplication and division, as the standard two's complement maths that the 6502 supports won't work.įor example, let's try adding 127 and -1 as sign-magnitude numbers, first using sign-magnitude arithmetic. The classic examples are the ship coordinates at INWK, which are stored in 24 bits as as (x_sign x_hi x_lo), where bit 7 of x_sign is the sign, and (x_hi x_lo) is the coordinate value. Doing basic arithmetic with sign-magnitude numbersĮlite uses a lot of sign-magnitude numbers, where the sign bit is stored separately from an unsigned magnitude. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |