A helpful tool I just made
Posted: Fri Jul 25, 2008 11:57 am
It prints out the assembly instructions for printing to the text console quickly. It doesn't check for newlines and such, but if you are using GCC it will automatically select the appropriate register, and with -DNASM on the command line, it printss out Intel syntax.
Hope it's useful to someone else.
Hope it's useful to someone else.
Code: Select all
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __x86_64__
#define REG "rax"
#else
#define REG "eax"
#endif
#ifdef NASM
#define TMPL \
"\tmov "REG", 0b8000h\n" \
"\tmov ["REG"+0%02xh], 0%04xh\n\n"
#else
#define TMPL \
"\tmov $0xb8000, %%"REG"\n" \
"\tmovw 0x%04x, 0x%02x(%%"REG")\n\n"
#endif
int main(int argc, char **argv) {
char *string = NULL;
unsigned int clr = 0;
unsigned int i = 0;
string = strdup((char*)argv[1]);
sscanf(argv[2],"%x", &clr);
if(argc != 3) {
fputs("Need two arguments.",stderr);
exit(1);
}
printf("INSTR: %s\n", string);
printf("----------[snip]----------\n");
for(i=0;i<strlen(string);i++) {
printf(TMPL,(clr<<0x8|string[i]),(i*2));
}
printf("----------[snip]----------\n");
free(string);
return 0;
}