forked from TCShenanigans/symphony_stdlib
Compare commits
45
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7621187e6 | ||
|
|
560855f6ac | ||
|
|
0ad8cf639c | ||
|
|
51c7869ce4 | ||
|
|
443623c945 | ||
|
|
a91895b8ac | ||
|
|
ef80825f40 | ||
|
|
d0afb22568 | ||
|
|
a4ecadfad5 | ||
|
|
6e5d0acfeb | ||
|
|
1508c22fc7 | ||
|
|
2b85e5a851 | ||
|
|
cbdcec77b5 | ||
|
|
6686bc54fc | ||
|
|
eb9dbfb8ad | ||
|
|
75da3d730f | ||
|
|
267dcba57d | ||
|
|
0894cdca40 | ||
|
|
a3f74a1f05 | ||
|
|
f91c56deb1 | ||
|
|
63e9d43440 | ||
|
|
8a463207ae | ||
|
|
98ecc3619c | ||
|
|
6be5e520bc | ||
|
|
bb4095b8fc | ||
|
|
bda60bd486 | ||
|
|
46e8fad974 | ||
|
|
993bbb797d | ||
|
|
7a9f2da1c0 | ||
|
|
db8462a2fe | ||
|
|
aa5cc1dbe0 | ||
|
|
f7d3ca2ec5 | ||
|
|
da811fd65d | ||
|
|
49767b61df | ||
|
|
6eb91f3433 | ||
|
|
9220e3dc28 | ||
|
|
25ecd155e1 | ||
|
|
c071a00746 | ||
|
|
5400da0157 | ||
|
|
f19dfd3611 | ||
|
|
a9fa16a241 | ||
|
|
de9ac7fe72 | ||
|
|
1fc4515f6b | ||
|
|
f4ae43bbc1 | ||
|
|
f27715b5b3 |
@@ -0,0 +1,21 @@
|
|||||||
|
# Memory Map
|
||||||
|
|
||||||
|
To not have to allocate a ton of things at run time the Standard Library uses a static memory map for some purposes
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
| Start | Use |
|
||||||
|
| ---- | ---- |
|
||||||
|
| `0x0` | Reset Vector |
|
||||||
|
| `0x16` | Zero Page |
|
||||||
|
| `0x100` | User Code |
|
||||||
|
| `?` | Library Code |
|
||||||
|
| `0x1_0000` | LUTs |
|
||||||
|
| `?` | heap |
|
||||||
|
| `0xXXF0_0000` | Stack |
|
||||||
|
| `0xXXFF_0000` | quick access |
|
||||||
|
|
||||||
|
## Zero Page
|
||||||
|
Some values are needed not often enough to get their own special register, but often enough that it makes sense to keep them at a quickly accessible location.
|
||||||
|
This is what the zero page is for. its position in memory allows us to load them into a register with a single instruction.
|
||||||
|
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
This is a standard library for symphony.
|
This is a standard library for symphony.
|
||||||
It is both intended as a practical toolkit to develop more complex software as well as a teaching resource.
|
It is both intended as a practical toolkit to develop more complex software as well as a teaching resource.
|
||||||
|
|
||||||
If you just want to use the standard library [[src/stdlib.asm]] is your main header, include it after your code.
|
If you just want to use the standard library [[stdlib.asm]] is your main header, include it after your code.
|
||||||
|
You also need to include [[globals.asm]] as the first line in your assembly file.
|
||||||
|
|
||||||
If you are using it as a learning resource have a look at the [teaching folder](teaching).
|
If you are using it as a learning resource have a look at the [teaching folder](teaching).
|
||||||
|
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
jmp 0x100
|
||||||
|
|
||||||
|
@0x10
|
||||||
|
screen:
|
||||||
|
frambuffer_ptr: U32 0x0
|
||||||
|
size: U32 0x0
|
||||||
|
position_xy: U32 0x0
|
||||||
|
mode: U32 0x0
|
||||||
|
|
||||||
|
@0x100
|
||||||
+14
-45
@@ -4,53 +4,22 @@
|
|||||||
; r2 - The second value
|
; r2 - The second value
|
||||||
; Result:
|
; Result:
|
||||||
; r1 - The lower 32 bits of the result
|
; r1 - The lower 32 bits of the result
|
||||||
; Clobbers: r2, r3, r4, r5, r6
|
; Clobbers: r2, r3, r4, r5
|
||||||
pub mul_low:
|
pub mul_low:
|
||||||
cmp r1, r2
|
mov r3, 0 ; result
|
||||||
jbe mul_low_noswap
|
mov r4, 31 ; loop counter
|
||||||
xor r1, r2, r1
|
|
||||||
xor r2, r1, r2
|
mul_low_loop:
|
||||||
xor r1, r2, r1
|
asr r5, r2, 31
|
||||||
; Passthrough
|
and r5, r5, r1
|
||||||
|
lsl r5, r5, r4
|
||||||
; Multiplies r1 and r2, returning the lower part of the result
|
add r3, r3, r5
|
||||||
; This method assumes r1 is smaller than r2, which results in faster execution
|
lsl r2, r2, 1
|
||||||
; Arguments:
|
sub r4, r4, 1
|
||||||
; r1 - The first value
|
cmp r4, 0
|
||||||
; r2 - The second value
|
jge mul_low_loop
|
||||||
; Result:
|
mov r1, r3
|
||||||
; r1 - The lower 32 bits of the result
|
|
||||||
; Clobbers: r2, r3, r4, r5, r6
|
|
||||||
pub mul_low_noswap:
|
|
||||||
mov r4, 0 ; r4 has the result
|
|
||||||
mov r6, mul_loop_end
|
|
||||||
add r3, r2, r2
|
|
||||||
|
|
||||||
mul_loop:
|
|
||||||
and r5, r1, 14 ; Taking the first four bits, discarding the odd
|
|
||||||
lsl r5, r5, 1 ; 0000 - 0, 0001 - 2, 0010 - 4, 0011 - 8, etc.
|
|
||||||
sub r5, r6, r5
|
|
||||||
jmp r5
|
|
||||||
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
add r4, r4, r3
|
|
||||||
mul_loop_end:
|
|
||||||
mov flags, r1
|
|
||||||
jne mul_skip_one
|
|
||||||
add r4, r4, r2
|
|
||||||
mul_skip_one:
|
|
||||||
lsl r2, r2, 4
|
|
||||||
lsl r3, r3, 4
|
|
||||||
lsr r1, r1, 4
|
|
||||||
cmp r1, zr
|
|
||||||
jne mul_loop
|
|
||||||
|
|
||||||
mov r1, r4
|
|
||||||
jmp r13
|
jmp r13
|
||||||
|
|
||||||
; Calculates the absolute value of the value provided in the r1 register
|
; Calculates the absolute value of the value provided in the r1 register
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
pub include bit
|
pub include bit
|
||||||
pub include imath
|
pub include imath
|
||||||
pub include array
|
|
||||||
pub include console
|
pub include console
|
||||||
|
|
||||||
; Needs to be last!
|
; Needs to be last!
|
||||||
|
|||||||
Reference in New Issue
Block a user