why do you need a to "psedo" a CPU instruction set (ASM)? seems kinda pointless to me :\ . why don't you just make a real assembler (lol)?
Printable View
why do you need a to "psedo" a CPU instruction set (ASM)? seems kinda pointless to me :\ . why don't you just make a real assembler (lol)?
is this what you want (pardon my D :( )?
there are some bugs -- mainly if I try to 'mov' anything else besides ax, it gets the value wrong.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;
}
pardon the D code again -- it shouldn't be that hard to translate to C/C++
Oh, okay. If that's all you want, then all you need to do is write a text parser. Input a text file with assembly mnemonics, and opcodes, and do what they say.
very simple. The parser is the hardest part and that isn't very hard. There are fine examples of parsers elsewhere on this board. I would say you should be able to do that in a week or two without much difficulty.
No timing issues, no binary, nothing hard.
yeah, im not a genius at programming and I could do something like that. this is a question that if answered might help him to(i also need it answered), what is the best way to parse a file without using alot of switch/if/else statements?Quote:
No timing issues, no binary, nothing hard.