I need to parse an assembly program. I have no problems parsing a group of instructions or a group of instructions with one loop. For example:
LD R2, 0(R1)
DADD R4, R2, R3
SD 0(R1), R4
DADDI R1, R1, #-8
DADD R2, R2, R4
or
Loop: LD R2, 0(R1)
DADD R4, R2, R3
SD 0(R1), R4
DADDI R1, R1, #-8
BNEZ R1, Loop
DADD R2, R2, R4
My problem is when there are nested loops. For example:
Loop: LD R2, 0(R1)
Loop: LD R2, 0(R1)
DADD R4, R2, R3
SD 0(R1), R4
DADDI R1, R1, #-8
BNEZ R1, Loop
DADD R2, R2, R4
DADD R4, R2, R3
SD 0(R1), R4
DADDI R1, R1, #-8
BNEZ R1, Loop
DADD R2, R2, R4
I was hoping that someone could provide some insight on how to parse the nested loop example. I would like to split the nested loops into 2 separate lists, innerLoop and outerLoop. The only way I see to do this is to count the whitespace or indentation to break it up. If anyone has a better idea, please let me know. Thanks!