I am working on a school project to write a program that detects data dependencies after reading in assembly instructions. I have a list of lists containing instructions.
One such example is a list, for example, line1 = [[ld a8,0x8910] [mul a3, a2,8] [shl a3, a3,4] [Add a3, a3, a8]]
Here, the last add command depends on the result of the left (shl) shift, which in turn depends on the result of mul intsruction.
I want my code to output the dependency as {mul → sh → add}
Another example: line2 = [[add a3, a2, a1] [sub a4, a5, a6] [add a9, a2, a4]] output: {add → add} {sub → add}
I want to delete the command codes to get the string1 = [[ a8 , 0x8910] [ a3 , a2,8] [ a3 , a3,4] [ a3 , a3, a8]] and then extract the destination operands in dst_list = [ a8, a3, a3, a3 } and the source operands to another list as src_list = [0x8910, [a2,8], [a3,4], [a3, a8]]. I am going to take the nth element from src_list and compare 0 through n-1 elements of dst_list and output the indices when they match. Finally, use a dictionary to display instructions that match my indexes. Is my approach right? Can someone help me on how to achieve this in python?
So far I have tried:
dest = re.findall( r'\[(?=([a-z0-9.]+))',str(line))
src = re.findall( r'\,(?=([a-z0-9]+))', str(line))
for i in dest:
dst_list.append([i])
for j in src:
src_list.append(j)
for nth src_item in src_list:
for 0 to n-1 dst_items in dst_list:
if src_list[src_item] == dst_list[dst_item]
OUTPUT dst_item -> src_item
re.findall - ( 2 src ).
?