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.
|
||||
@@ -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
|
||||
|
||||
@@ -8,8 +8,8 @@ start:
|
||||
; Search the list until we find a prime.
|
||||
SETD DataTop
|
||||
CCF ; Clear the carry flag. In later cycles, the carry flag will be set at the end of the next loop. We'll want it cleared.
|
||||
INIA 0x00
|
||||
INIB 0x00
|
||||
RSTA
|
||||
RSTB
|
||||
findPrimeLoop:
|
||||
LDB ; Load an element into B.
|
||||
BRB foundPrime ; If it's zero, it's a prime.
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
; This program asks the user for input, then prints whatever they input back to the console again.
|
||||
; It stores the input string in a buffer in the Data Memory.
|
||||
|
||||
#Include ../Libraries/print.asm
|
||||
|
||||
#Program
|
||||
|
||||
start:
|
||||
SETD Message0 ; Set the Data Pointer to the explanation message.
|
||||
CALL printString ; Print it out.
|
||||
CALL lineFeed
|
||||
SETD Buffer ; Set the Data Pointer to the start of the buffer.
|
||||
INIB 0x0A ; Load the value of a linefeed into B.
|
||||
inputLoop:
|
||||
INA 0x00 ; Poll the command line.
|
||||
CCF
|
||||
SUB
|
||||
BRQ inputEnd ; If we encountered a linefeed, the string is over, proceed to processing.
|
||||
STA ; Store A into the buffer.
|
||||
INCD ; Increment to the next spot in the buffer.
|
||||
BRI inputLoop ; Loop again to grab more string.
|
||||
inputEnd:
|
||||
INIA 0x00 ; Set A to 0.
|
||||
STA ; Store it in the buffer.
|
||||
SETD Buffer ; Set the Data Pointer to the start of the buffer again.
|
||||
CALL printString ; Print it out.
|
||||
CALL lineFeed
|
||||
HALT ; End the program.
|
||||
|
||||
#Data
|
||||
|
||||
; A 256 character buffer for the input string.
|
||||
; There will need to be some kind of way to define large arrays better than this...
|
||||
Buffer:
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
|
||||
Message0:
|
||||
"Input Test: Will echo anything you put in."
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
; A test for the new math subroutines.
|
||||
|
||||
#Include ../Libraries/print.asm
|
||||
#Include ../Libraries/math.asm
|
||||
|
||||
#Program
|
||||
start:
|
||||
SETD SomeInt16Operands
|
||||
CALL int16sub
|
||||
BRC end
|
||||
LDA
|
||||
CALL printByteHex
|
||||
INCD
|
||||
LDA
|
||||
CALL printByteHex
|
||||
INIA 0x3A
|
||||
OUTA 0x00
|
||||
BRI start
|
||||
end:
|
||||
CALL lineFeed
|
||||
HALT
|
||||
|
||||
#Data
|
||||
|
||||
SomeInt16Operands:
|
||||
0xFF 0xFF
|
||||
0x00 0x01
|
||||
Reference in New Issue
Block a user