Im trying to make SIC assembler in c, made a small test program to search for "START" keyword and get the starting address from the assembly code file. then write them in another file as first pass. code didn't work. mind telling whats wrong with it?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[])
{
FILE *source;
FILE *intermediate;
rewind(source);
char word[10];
unsigned int address = 0;
char start[5] = "START";
source = fopen(argv[1],"r");
intermediate = fopen(argv[2],"r+");
while(strcmp(word,start) != 0)
{
fscanf(source, "%s", word);
}
fscanf(source, "%x", address);
fprintf(intermediate, "%x", address);
fprintf(intermediate, "%s", word);
return(0);
}
this is the assembly input:
COPY START 1000
FIRST STL RETADR
CLOOP JSUB RDREC
LDA LENGTH
COMP ZERO
JEQ ENDFIL
JSUB WRREC
J CLOOP
ENDFIL LDA EOF
STA BUFFER
LDA THREE
STA LENGTH
JSUB WRREC
LDL RETADR
RSUB
EOF BYTE C'EOF'
THREE WORD 3
ZERO WORD 0
RETADR RESW 1
LENGTH RESW 1
BUFFER RESB 4096