9 changed files with 52 additions and 15 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
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 [[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). If you are using it as a learning resource have a look at the [teaching folder](teaching).
+3
View File
@@ -0,0 +1,3 @@
# Examples
Examples of how to use the standard library to accomplish a task.
View File
View File
View File
View File
+45 -14
View File
@@ -4,22 +4,53 @@
; 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 ; Clobbers: r2, r3, r4, r5, r6
pub mul_low: pub mul_low:
mov r3, 0 ; result cmp r1, r2
mov r4, 31 ; loop counter jbe mul_low_noswap
xor r1, r2, r1
mul_low_loop: xor r2, r1, r2
asr r5, r2, 31 xor r1, r2, r1
and r5, r5, r1 ; Passthrough
lsl r5, r5, r4
add r3, r3, r5 ; Multiplies r1 and r2, returning the lower part of the result
lsl r2, r2, 1 ; This method assumes r1 is smaller than r2, which results in faster execution
sub r4, r4, 1 ; Arguments:
cmp r4, 0 ; r1 - The first value
jge mul_low_loop ; r2 - The second value
mov r1, r3 ; 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 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
View File
+3
View File
@@ -0,0 +1,3 @@
# Tests
Tests for the standard library go here, tests are allowed to depend on the recommended spec.isa changes.