forked from TCShenanigans/symphony_stdlib
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
993bbb797d | ||
|
|
7a9f2da1c0 | ||
|
|
db8462a2fe | ||
|
|
aa5cc1dbe0 | ||
|
|
f7d3ca2ec5 | ||
|
|
da811fd65d | ||
|
|
49767b61df | ||
|
|
6eb91f3433 | ||
|
|
9220e3dc28 | ||
|
|
25ecd155e1 | ||
|
|
c071a00746 | ||
|
|
5400da0157 | ||
|
|
f19dfd3611 | ||
|
|
a9fa16a241 | ||
|
|
de9ac7fe72 | ||
|
|
1fc4515f6b | ||
|
|
f4ae43bbc1 | ||
|
|
f27715b5b3 |
+2
-2
@@ -16,8 +16,8 @@ All functions in the standard library should follow the following outline:
|
||||
; Arguments: <which register contains what argument>
|
||||
; Result: <what is the result, and where is it stored>
|
||||
; Clobbers: <list of registers that are clobbered>
|
||||
<label>: <;SHOULD BE INLINED>
|
||||
<CODE>
|
||||
fn_label: <;SHOULD BE INLINED>
|
||||
CODE
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.
|
||||
|
||||
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).
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
jmp 0x100
|
||||
|
||||
@0x10
|
||||
screen:
|
||||
frambuffer_ptr: U32 0x0
|
||||
size: U32 0x0
|
||||
position_xy: U32 0x0
|
||||
mode: U32 0x0
|
||||
|
||||
@0x100
|
||||
@@ -1,15 +1,8 @@
|
||||
; Multiplies r1 and r2, returning the lower part of the result
|
||||
; Arguments:
|
||||
; r1 - The first value
|
||||
; r2 - The second value
|
||||
; Result:
|
||||
; r1 - The lower 32 bits of the result
|
||||
; Clobbers: r2, r3, r4, r5
|
||||
pub mul_low:
|
||||
mov r3, 0 ; result
|
||||
mov r4, 31 ; loop counter
|
||||
|
||||
mul_low_loop:
|
||||
mull_loop:
|
||||
asr r5, r2, 31
|
||||
and r5, r5, r1
|
||||
lsl r5, r5, r4
|
||||
@@ -17,18 +10,14 @@ pub mul_low:
|
||||
lsl r2, r2, 1
|
||||
sub r4, r4, 1
|
||||
cmp r4, 0
|
||||
jge mul_low_loop
|
||||
jge mull_loop
|
||||
mov r1, r3
|
||||
|
||||
jmp r13
|
||||
|
||||
; Calculates the absolute value of the value provided in the r1 register
|
||||
; Arguments:
|
||||
; r1 - The value for which we want the absolute value
|
||||
; Result:
|
||||
; r1 - The calculated absolute value
|
||||
; Clobbers: r2
|
||||
; Info: Based on Stanford's BitHacks
|
||||
; Based on Stanford's BitHacks
|
||||
; Clobbers r2
|
||||
pub abs: ; SHOULD BE INLINED
|
||||
; mask = v >> 31
|
||||
asr r2, r1, 31
|
||||
@@ -39,13 +28,8 @@ pub abs: ; SHOULD BE INLINED
|
||||
jmp r13
|
||||
|
||||
; Calculates the minimum value of the two values provided in the r1 and r2 registers
|
||||
; Arguments:
|
||||
; r1 - The first value
|
||||
; r2 - The second value
|
||||
; Result:
|
||||
; r1 - The smaller value
|
||||
; Clobbers: Nothing
|
||||
; Info: Based on Stanford's BitHacks
|
||||
; Based on Stanford's BitHacks
|
||||
; Clobbers flags
|
||||
pub min: ; SHOULD BE INLINED
|
||||
; x < y
|
||||
cmp r1, r2
|
||||
@@ -61,13 +45,8 @@ pub min: ; SHOULD BE INLINED
|
||||
jmp r13
|
||||
|
||||
; Calculates the maximum value of the two values provided in the r1 and r2 registers
|
||||
; Arguments:
|
||||
; r1 - The first value
|
||||
; r2 - The second value
|
||||
; Result:
|
||||
; r1 - The smaller value
|
||||
; Clobbers: r2
|
||||
; Info: Based on Stanford's BitHacks
|
||||
; Based on Stanford's BitHacks
|
||||
; Clobbers r2 and flags
|
||||
pub max: ; SHOULD BE INLINED
|
||||
; x < y
|
||||
cmp r1, r2
|
||||
|
||||
Reference in New Issue
Block a user