More Programs
Added math library WIP. Added some other stuff.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
; A library of math subroutines for SplitBit.
|
||||
|
||||
#Program
|
||||
|
||||
int16add:
|
||||
; Add two two-byte unsigned integers.
|
||||
; Operands are stored in a four-byte array in the following order:
|
||||
; Operand A, high byte
|
||||
; Operand A, low byte
|
||||
; Operand B, high byte
|
||||
; Operand B, low byte
|
||||
; The result is stored by overwriting Operand A.
|
||||
; This subroutine expects the Data Pointer to be set to the start of the array.
|
||||
; After execution, this routine leaves the data pointer set to the high byte of the result.
|
||||
; If the addtion results in a carry, the carry flag will be set.
|
||||
CCF ; Clear the Carry Flag, just in case.
|
||||
DPUP 0d03 ; Move to Operand B's low byte.
|
||||
LDB ; Load it to B.
|
||||
DPDN 0d02 ; Move to Operand A's low byte.
|
||||
LDA ; Load it to A.
|
||||
ADD ; Add them together.
|
||||
STQ ; Store the result.
|
||||
INCD ; Go to Operand B's high byte.
|
||||
LDB ; Load it to B.
|
||||
DPDN 0d02 ; Go to Operand A's high byte.
|
||||
LDA ; Load it to A.
|
||||
ADD ; Add them together.
|
||||
STQ ; Store the result.
|
||||
RET ; Return to the caller.
|
||||
|
||||
int16sub:
|
||||
; Subtract two two-byte unsigned integers.
|
||||
; Operands are stored in a four-byte array in the following order:
|
||||
; Operand A, high byte
|
||||
; Operand A, low byte
|
||||
; Operand B, high byte
|
||||
; Operand B, low byte
|
||||
; Operand B is subtracted from Operand A and the result is stored by overwriting Operand A.
|
||||
; This subroutine expects the Data Pointer to be set to the start of the array.
|
||||
; After execution, this routine leaves the data pointer set to the high byte of the result.
|
||||
; If the addtion results in a carry, the carry flag will be set.
|
||||
CCF ; Clear the Carry Flag, just in case.
|
||||
DPUP 0d03 ; Move to Operand B's low byte.
|
||||
LDB ; Load it to B.
|
||||
DPDN 0d02 ; Move to Operand A's low byte.
|
||||
LDA ; Load it to A.
|
||||
SUB ; Subtract B from A.
|
||||
STQ ; Store the result.
|
||||
INCD ; Go to Operand B's high byte.
|
||||
LDB ; Load it to B.
|
||||
DPDN 0d02 ; Go to Operand A's high byte.
|
||||
LDA ; Load it to A.
|
||||
SUB ; Subtract B from A.
|
||||
STQ ; Store the result.
|
||||
RET ; Return to the caller.
|
||||
|
||||
#Data
|
||||
|
||||
Int16operands:
|
||||
0x00 ; Operand A high byte.
|
||||
0x00 ; Operand A low byte.
|
||||
0x00 ; Operand B high byte.
|
||||
0x00 ; Operand B low byte.
|
||||
@@ -32,7 +32,7 @@ printString: ; Expects Data Pointer to be set to the beginning of
|
||||
INCD ; Increment Data Pointer to the next character.
|
||||
BRI printString ; Branch to the beginning of the loop.
|
||||
printDone:
|
||||
RET ; Return to the caller.
|
||||
RET ; Return to the caller.
|
||||
|
||||
; Expects A to contain the value to be printed in decimal form.
|
||||
printByteDecimal:
|
||||
@@ -132,6 +132,8 @@ DecimalValue:
|
||||
0x00 ; The tens place.
|
||||
0x00 ; The hundreds place.
|
||||
|
||||
; For convenience, I'll pad this out so programs using this library store their data in a fresh page of memory.
|
||||
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
|
||||
Reference in New Issue
Block a user