I'm trying to create an Instruction Set Simulator that reads in assembly and executes the desired action. Each line consists of [address][instruction][input1] and possibly also [input2]
The file I'm reading looks like this:
10 MOV R1, 1
11 MOV R2, 10
12 MOV R3, 101
13 ST [R3], R1
14 ADD R1, 1
15 ADD R3, 1
16 CMP R1, R2
17 JE 19
18 JMP 13
19 MOV R2, 5
20 MOV R4, 0
21 MOV R3, 109
22 MOV R1, -1
23 LD R5, [R3]
24 ADD R3, R1
25 ADD R4, 1
26 CMP R4, R2
27 JE 29
28 JMP 23
29 MOV R3, 120
30 ST [R3], R5
and right now I'm trying to parse each line using fscanf:
char* buf[100];
while (fscanf(fptr,"%*s %3s %*s %*s ",buf)==1)
printf("%s\n", buf);
The output I'm getting is this:
MOV
MOV
ST
ADD
ADD
CMP
JE
13
5
0
109
-1
[R3
R3,
R4,
R4,
29
29
30
Could someone explain what's happening and suggest a way to capture each part of the instruction?
Thank you!