Skip to content

Commit ba48ff2

Browse files
authored
Merge pull request #2 from celebi-pkg/dev
Fixing README, updating reference to repo, package changelog, etc
2 parents cf8a3e2 + a9f1160 commit ba48ff2

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ author_email = kayacelebi17@gmail.com
55
description = RISC-V Assembly code assembler package for Python.
66
long_description = file: README.md
77
long_description_content_type = text/markdown
8-
url = https://github.com/kcelebi/riscv-assembler
8+
url = https://github.com/celebi-pkg/riscv-assembler
99
project_urls =
10-
Bug Tracker = https://github.com/kcelebi/riscv-assembler/issues
11-
Changelog = https://github.com/kcelebi/riscv-assembler/releases
10+
Bug Tracker = https://github.com/celebi-pkg/riscv-assembler/issues
11+
Changelog = https://github.com/celebi-pkg/riscv-assembler/releases
1212
classifiers =
1313
Programming Language :: Python :: 3
1414
License :: OSI Approved :: MIT License

src/riscv_assembler/instr_arr.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ def JUMP(tk : str, line_num : int, code: list) -> int:
184184
try:
185185
index, skip_labels = code.index(tk + ":"), 0
186186
except:
187-
raise Exception('''Address not found! Provided assembly code could
188-
be faulty, branch is expressed but not found in code.''')
187+
raise Exception('''Address not found for {}! Provided assembly code could
188+
be faulty, branch is expressed but not found in code.'''.format(tk))
189189

190190
pos = 1
191191
if index > line_num: # forward search:
@@ -298,6 +298,7 @@ def __str__(self):
298298
def organize(self, tokens):
299299
# better way to organize, express, abstract pseudo?
300300
instr = tokens[0]
301+
line_num, code = tokens[-2], tokens[-1]
301302
if instr == 'nop':
302303
rs1, imm, rd = reg_map["x0"], 0, reg_map["x0"]
303304
return I("addi", rs1, imm, rd)
@@ -310,8 +311,14 @@ def organize(self, tokens):
310311
elif instr == "neg":
311312
rs1, rs2, rd = reg_map["x0"], reg_map[tokens[2]], reg_map[tokens[1]]
312313
return R("sub", rs1, rs2, rd)
313-
314-
raise Exception("Bad Instruction provided, this does not exist or has not been implemented here yet.")
314+
elif instr == "j":
315+
return UJ("jal", super().JUMP(tokens[1], line_num, code), "x0")
316+
elif instr == "li":
317+
# This is missing addi rd rd -273
318+
return U("lui", tokens[2], reg_map[tokens[1]])
319+
# I("addi", reg_map[tokens[1]], reg_map[tokens[1]], tokens[2])
320+
321+
raise Exception("Bad Instruction provided, {} does not exist or has not been implemented here yet.".format(instr))
315322

316323

317324
def register_map():

tests/assembly/test8.s

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
dot:
2+
addi sp, sp, -24
3+
sw s0, 0(sp) #sum
4+
sw s1, 4(sp) #loaded val v0
5+
sw s2, 8(sp) #loaded val v1
6+
sw s3, 12(sp) #product
7+
sw s4, 16(sp) #stride v0
8+
sw s5, 20(sp) #stride v1
9+
10+
addi t5, x0, 1 #exit value
11+
blt a2, t5, exit5
12+
blt a3, t5, exit6
13+
blt a4, t5, exit6
14+
j loop_start
15+
16+
exit5:
17+
li a1, 5
18+
j exit6
19+
20+
exit6:
21+
li a1, 6
22+
j exit5
23+
24+
loop_start:
25+
addi s0, x0, 0 #set sum to 0
26+
addi t0, x0, 0 #i=0, to keep track of not going over vectorsize
27+
addi t1, x0, 0 #v0 iter = 0
28+
addi t2, x0, 0 #v1 iter = 0
29+
addi t3, x0, 4
30+
mul s4, a3, t3 #v0 stride
31+
mul s5, a4, t3 #v1 stride
32+
33+
j loop_continue
34+
35+
loop_continue:
36+
beq t0, a2, loop_end #loop statement
37+
38+
lw s1, 0(a0) #load v0
39+
lw s2, 0(a1) #load v1
40+
41+
add a0, a0, s4 #getting v0[i], increment by stride
42+
add a1, a1, s5 #getting v1[i], increment by stride
43+
44+
mul s3, s1, s2 #get product
45+
46+
add s0, s0, s3 #add to sum
47+
48+
addi t0, t0, 1 #increment
49+
j loop_continue
50+
51+
loop_end:
52+
# Epilogue
53+
mv a0, s0 #give a0 return value
54+
55+
lw s0, 0(sp) #restore and end
56+
lw s1, 4(sp)
57+
lw s2, 8(sp)
58+
lw s3, 12(sp)
59+
lw s4, 16(sp)
60+
lw s5, 20(sp)
61+
addi, sp, sp, 24
62+
#ret

tests/test_class.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from riscv_assembler.instr_arr import *
66
from riscv_assembler.parse import Parser
77

8-
num_test_files = 8
8+
num_test_files = 9
99
num_questions = 15
1010

1111
def SUITE():
@@ -85,6 +85,7 @@ def SUITE():
8585

8686
return results
8787

88+
ans = ['0xfe810113','0x00812023','0x00912223','0x01212423','0x01312623','0x01412823','0x01512a23','0x00100f13','0x01e64863','0x01e6ca63','0x01e74863','0x0140006f','0x00500593','0xfcdff06f','0x00600593','0xfc5ff06f','0x00000413','0x00000293','0x00000313','0x00000393','0x00400e13','0x03c68a33','0x03c70ab3','0x0040006f','0x02c28263','0x00052483','0x0005a903','0x01450533','0x015585b3','0x032489b3','0x01340433','0x00128293','0xfe1ff06f','0x00040513','0x00012403','0x00412483','0x00812903','0x00c12983','0x01012a03','0x01412a83','0x01810113']
8889
ANSWERS = {
8990
0: [['0x000000b3'], None, 'file0.txt', 'file0.bin', ['0x000000b3'], None, 'str0.txt', 'str0.bin', ['0x000000b3'], 'a', None, 'p', 'arr0.txt', 'arr0.bin', 'f'],
9091
1: [['0x02040293'], None, 'file1.txt', 'file1.bin',['0x02040293'], None, 'str1.txt', 'str1.bin',['0x02040293'], 'a', None, 'p', 'arr1.txt', 'arr1.bin', 'f'],
@@ -93,7 +94,9 @@ def SUITE():
9394
4: [['0x000000b3', '0x02040293', '0x02040293','0x00812023'], None, 'file4.txt', 'file4.bin',['0x000000b3', '0x02040293', '0x02040293','0x00812023'], None, 'str4.txt', 'str4.bin',['0x000000b3', '0x02040293', '0x02040293','0x00812023'], 'a', None, 'p', 'arr4.txt', 'arr4.bin', 'f'],
9495
5: [['0x00a00413','0x00a00493','0xfff00493','0x00048463','0xfe000ce3','0xfe040493'], None, 'file5.txt', 'file5.bin', ['0x00a00413','0x00a00493','0xfff00493','0x00048463','0xfe000ce3','0xfe040493'], None, 'str5.txt', 'str5.bin', ['0x00a00413','0x00a00493','0xfff00493','0x00048463','0xfe000ce3','0xfe040493'], 'a', None, 'p', 'arr5.txt', 'arr5.bin', 'f'],
9596
6: [['0x00a00093','0xfec00113','0x00000663','0x00123023','0x00023083','0xfff00093','0x00123023','0x00023083','0xfe02c6e3'], None, 'file6.txt', 'file6.bin', ['0x00a00093','0xfec00113','0x00000663','0x00123023','0x00023083','0xfff00093','0x00123023','0x00023083','0xfe02c6e3'], None, 'str6.txt', 'str6.bin', ['0x00a00093','0xfec00113','0x00000663','0x00123023','0x00023083','0xfff00093','0x00123023','0x00023083','0xfe02c6e3'], 'a', None, 'p', 'arr6.txt', 'arr6.bin', 'f'],
96-
7: [['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], None, 'file7.txt', 'file7.bin', ['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], None, 'str7.txt', 'str7.bin', ['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], 'a', None, 'p', 'arr7.txt', 'arr7.bin', 'f']}
97+
7: [['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], None, 'file7.txt', 'file7.bin', ['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], None, 'str7.txt', 'str7.bin', ['0x00318233','0x002080b3','0x00708093','0x00123023','0x00023083'], 'a', None, 'p', 'arr7.txt', 'arr7.bin', 'f'],
98+
8: [ans, None, 'file8.txt', 'file8.bin', ans, None, 'str8.txt', 'str8.bin', ans, 'a', None, 'p', 'arr8.txt', 'arr8.bin', 'f']}
99+
97100
RESULTS = SUITE()
98101

99102
def error_label(q, test):

0 commit comments

Comments
 (0)