aslfaqs
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| aslfaqs [2025/09/20 16:53] – [How do negative numbers work?] reggie | aslfaqs [2025/09/23 17:33] (current) – [How do negative numbers work?] reggie | ||
|---|---|---|---|
| Line 365: | Line 365: | ||
| decb ; loop count | decb ; loop count | ||
| bne sprEraseLoop | bne sprEraseLoop | ||
| - | rts | + | rts |
| - | | + | |
| ==== How do I use local variables? ==== | ==== How do I use local variables? ==== | ||
| Line 538: | Line 537: | ||
| ==== What is indirection and how do I use it? ==== | ==== What is indirection and how do I use it? ==== | ||
| - | The standard way of accessing a variable in memory is via **direct extended** addressing. A 16-bit address is given, and an 8 or 16 bit operand is read from this ' | + | The standard way of accessing a variable in memory is via **direct extended** addressing. A 16-bit address is given, and an 8 or 16 bit operand is read from this ' |
| CURSPOS rmb 2 | CURSPOS rmb 2 | ||
| Line 544: | Line 543: | ||
| ldx # | ldx # | ||
| ldd # | ldd # | ||
| - | std ,x | + | std ,x |
| stx CURSPOS | stx CURSPOS | ||
| | | ||
| ldb [CURSPOS] ; what character is at the cursor position? | ldb [CURSPOS] ; what character is at the cursor position? | ||
| rts | rts | ||
| - | |||
| - | As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit address, auto-increment/ | ||
| As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit addresss, auto-increment/ | As well as direct extended mode, indirection can be used on PC relative and indexed addressing modes too. But note that because we are always specifying a 16-bit addresss, auto-increment/ | ||
| Line 569: | Line 566: | ||
| clr ,-s ; reserve and zero value of longest strng so far | clr ,-s ; reserve and zero value of longest strng so far | ||
| loop: | loop: | ||
| - | lda [, | + | lda [, |
| cmpa ,s ; is A higher than longest? | cmpa ,s ; is A higher than longest? | ||
| bls short ; skip if not | bls short ; skip if not | ||
| Line 654: | Line 651: | ||
| ==== How do negative numbers work? ==== | ==== How do negative numbers work? ==== | ||
| - | Fill in later. | + | Think of an old-fashioned clock face as an analogy with an 8-bit register. An hour has 60 minutes, marked as 0 to 59. The minute hand goes only one way, and when it come round to zero the hour hand advances. |
| + | |||
| + | An 8-bit register has 256 values, marked as 0 to 255, and when it overflows round to zero the carry flag is set. | ||
| + | |||
| + | How do negative numbers work on a clock? It's entirely down to how we choose to read them. We can say " | ||
| + | |||
| + | In binary the principle works just the same, only (for an 8-bit value) we subtract from 256 instead of 60, ie. "minus ten" equals " | ||
| + | |||
| + | Which signed numbers are positive and which negative? Highest bit set means negative, so unsigned values 128 to 255 represent -128 to -1. Positive signed values range from 0 to 127. This is called " | ||
| + | |||
| + | This format is chosen because the underlying circuitry doesn' | ||
| + | |||
| + | Which instructions deal with signed numbers? There' | ||
| + | |||
| + | Signed branches | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | Miscellaneous instructions | ||
| + | |||
| + | NEG (8-bit only) | ||
| + | SEX Sign EXtend B to D | ||
| + | COMA; COMB; ADDD #1 negate D | ||
| + | |||
| + | Note that other than the simple BPL/BMI, the signed variants are not commonly used. If you do choose one, think twice whether you meant the unsigned variant. Signed comparisons should not be used with addresses for example. | ||
| + | |||
| + | |||
| + | |||
| ==== What do all the instructions do? ==== | ==== What do all the instructions do? ==== | ||
| [Will get round to this one] | [Will get round to this one] | ||
aslfaqs.1758387206.txt.gz · Last modified: 2025/09/20 16:53 by reggie
