is this what you want (pardon my D )?
Code:
/*
CASM - a "psedo"-asmbler
by Samuel Fredrickson
*/
import std.c.stdio;
/* global registers - just the basics*/
char[2] ax;
char[2] bx;
char[2] cx;
char[2] dx;
void mov(char[32] line)
{
if(line[3] != ' ')
{
printf("ERROR: mov syntax is \'mov [dest],[value]\'\n");
}
if(line[4] == 'a' && line[5] == 'x')
{
ax[0] = line[7];
ax[1] = line[8];
printf("ax = %c%c\n",ax[0],ax[1]);
return;
}
else if(line[4] == 'b' && line[5] == 'x')
{
bx[0] = line[7];
bx[1] = line[8];
printf("bx = %c%c\n",ax[0],ax[1]);
return;
}
else if(line[4] == 'c' && line[5] == 'x')
{
cx[0] = line[7];
cx[1] = line[8];
printf("bx = %c%c\n",ax[0],ax[1]);
return;
}
else if(line[4] == 'd' && line[5] == 'x')
{
dx[0] = line[7];
dx[1] = line[8];
printf("dx = %c%c\n",ax[0],ax[1]);
return;
}
}
int main(char[][] args)
{
char *filename;
FILE *f;
static char buff[32];
int i;
for(i = 0;i <= args.length;i++)
{
if(args[i] == "-f")
{
filename = args[i+1];
}
}
if( (f = fopen(filename,"r")) == null)
{
printf("ERROR: Could not Open File");
return 0;
}
// get line information
while((fgets(buff,32,f)) != null)
{
if(buff[0] == 'm' && buff[1] == 'o' && buff[2] == 'v')
{
mov(buff);
}
}
return 0;
}
there are some bugs -- mainly if I try to 'mov' anything else besides ax, it gets the value wrong.
pardon the D code again -- it shouldn't be that hard to translate to C/C++