forked from TCShenanigans/symphony_stdlib
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b97e17fa84 | ||
|
|
a00c7f2a84 | ||
|
|
c83269fcf7 | ||
|
|
6bf0c0a4fc | ||
|
|
697445feec | ||
|
|
7c49c5212e | ||
|
|
6ff1a43c32 |
@@ -3,7 +3,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.
|
||||
If you just want to use the standard library [[src/stdlib.asm]] is your main header, include it after your code.
|
||||
|
||||
If you are using it as a learning resource have a look at the [teaching folder](teaching).
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Examples
|
||||
|
||||
Examples of how to use the standard library to accomplish a task.
|
||||
+44
-13
@@ -4,22 +4,53 @@
|
||||
; r2 - The second value
|
||||
; Result:
|
||||
; r1 - The lower 32 bits of the result
|
||||
; Clobbers: r2, r3, r4, r5
|
||||
; Clobbers: r2, r3, r4, r5, r6
|
||||
pub mul_low:
|
||||
mov r3, 0 ; result
|
||||
mov r4, 31 ; loop counter
|
||||
cmp r1, r2
|
||||
jbe mul_low_noswap
|
||||
xor r1, r2, r1
|
||||
xor r2, r1, r2
|
||||
xor r1, r2, r1
|
||||
; Passthrough
|
||||
|
||||
mul_low_loop:
|
||||
asr r5, r2, 31
|
||||
and r5, r5, r1
|
||||
lsl r5, r5, r4
|
||||
add r3, r3, r5
|
||||
lsl r2, r2, 1
|
||||
sub r4, r4, 1
|
||||
cmp r4, 0
|
||||
jge mul_low_loop
|
||||
mov r1, r3
|
||||
; Multiplies r1 and r2, returning the lower part of the result
|
||||
; This method assumes r1 is smaller than r2, which results in faster execution
|
||||
; Arguments:
|
||||
; r1 - The first value
|
||||
; r2 - The second value
|
||||
; Result:
|
||||
; 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
|
||||
|
||||
; Calculates the absolute value of the value provided in the r1 register
|
||||
@@ -0,0 +1,3 @@
|
||||
# Tests
|
||||
|
||||
Tests for the standard library go here, tests are allowed to depend on the recommended spec.isa changes.
|
||||
Reference in New Issue
Block a user