Advertisement
Kitomas

kit-8 std/math.asm v0

Apr 13th, 2023
2,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef _STD_MATH_ASM
  2. #define _STD_MATH_ASM
  3. ;std/math.asm
  4. #include "pseudoOps.h"
  5.  
  6.  
  7. :math_ptrA: !16 0 ;pointers that hold locations to operands
  8. :math_ptrB: !16 0 ;^^
  9.  
  10. #ifdef MATH_USE_ADD
  11. /*  *ptrA += (signed)A  */
  12. :_add8s_16:
  13.     ldi #,0                             ;set index to 0 for low byte
  14.     and #,0xff && bns .sub              ;update n flag && branch to .sub if negative
  15.     lda @,L1ARG                         ;restore original contents of A
  16.     add *,math_ptrA && sta *,math_ptrA  ;add A to low byte && store result
  17.     ldi #,1 && lda *,math_ptrA          ;set index to 1 for high byte && load high byte
  18.     adc #,0 && sta *,math_ptrA          ;if carry set, increment && store result
  19.     jpr                                 ;return from subroutine
  20. .sub: ;(remember, it's A-memory, not memory-A)
  21.     lda @,L1ARG                         ;get two's complement of A
  22.     xor #,0xff && add #,1               ;^^(to make sure we're not subtracting
  23.     sta $,_SCRATCH_A                    ;^^ by a negative number)
  24.     sec                                 ;preemtively set carry flag so borrow isn't factored in
  25.     lda *,math_ptrA                     ;get low byte of 16-bit number
  26.     sbc @,_SCRATCH_A && sta *,math_ptrA ;subtract low byte by A && store result
  27.     bcs .r                              ;if no borrow, then skip decrement
  28.     ldi #,1 && lda *,math_ptrA          ;set index to 1 for high byte && load high byte
  29.     add #,-1 && sta *,math_ptrA         ;decrement high byte && store result
  30.                                         ;^^'add -1' instead of 'sec && sbc 1' so carry flag is ignored
  31. .r: jpr                                 ;return from subroutine
  32. /*  *ptrA += *ptrB  */
  33. :_add16_16:
  34.     ldi #,0 && lda *,math_ptrA          ;set index to 0 for low byte && load low byte
  35.     add *,math_ptrB && sta *,math_ptrA  ;add low bytes && store result
  36.     ldi #,1 && lda *,math_ptrA          ;set index to 1 for high byte && load high byte
  37.     adc *,math_ptrB && sta *,math_ptrA  ;add high bytes (+carry bit) && store result
  38.     jpr                                 ;return from subroutine
  39. #endif
  40.  
  41. #ifdef MATH_USE_SIN
  42. !bin "std/sin256_8.bin"
  43. #endif
  44.  
  45. #endif
Tags: kit-8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement