Rizin
unix-like reverse engineering framework and cli tools
8051_ass.h File Reference
#include <rz_asm.h>

Go to the source code of this file.

Functions

int assemble_8051 (RzAsm *a, RzAsmOp *op, char const *user_asm)
 

Function Documentation

◆ assemble_8051()

int assemble_8051 ( RzAsm a,
RzAsmOp op,
char const user_asm 
)

Definition at line 1183 of file 8051_ass.c.

1183  {
1184  if (!a || !op || !user_asm) {
1185  return 0;
1186  }
1187  rz_strbuf_set(&op->buf_asm, user_asm);
1188  while (!terminates_asm_line(*user_asm) && (*user_asm == ' ' || *user_asm == '\t')) {
1189  user_asm += 1;
1190  }
1191  char const *arguments = user_asm;
1192  while (!terminates_asm_line(*arguments) && (('a' <= *arguments && *arguments <= 'z') || ('A' <= *arguments && *arguments <= 'Z'))) {
1193  arguments += 1;
1194  }
1195  while (!terminates_asm_line(*arguments) && (*arguments == ' ' || *arguments == '\t')) {
1196  arguments += 1;
1197  }
1198  char *arg[3] = { 0 };
1199  int nr_of_arguments = get_arguments(arg, arguments);
1200  char const *carg[3] = { arg[0], arg[1], arg[2] }; /* aliasing pointers...
1201  I need to pass char const *s, but I can't free char const *s
1202  not without compiler warnings, at least */
1203  int wants_arguments;
1204  parse_mnem_args mnem = mnemonic(user_asm, &wants_arguments);
1205  if (!mnem || nr_of_arguments != wants_arguments) {
1206  free(arg[2]);
1207  arg[2] = 0;
1208  carg[2] = 0;
1209  free(arg[1]);
1210  arg[1] = 0;
1211  carg[1] = 0;
1212  free(arg[0]);
1213  arg[0] = 0;
1214  carg[0] = 0;
1215  return 0;
1216  }
1217  ut8 instr[4] = { 0 };
1218  ut8 *binp = instr;
1219  if (!mnem(carg, a->pc, &binp)) {
1220  free(arg[0]);
1221  arg[0] = 0;
1222  carg[2] = 0;
1223  free(arg[1]);
1224  arg[1] = 0;
1225  carg[1] = 0;
1226  free(arg[2]);
1227  arg[2] = 0;
1228  carg[0] = 0;
1229  return 0;
1230  } else {
1231  free(arg[0]);
1232  arg[0] = 0;
1233  carg[2] = 0;
1234  free(arg[1]);
1235  arg[1] = 0;
1236  carg[1] = 0;
1237  free(arg[2]);
1238  arg[2] = 0;
1239  carg[0] = 0;
1240  size_t len = binp - instr;
1241  rz_strbuf_setbin(&op->buf, instr, len);
1242  return binp - instr;
1243  }
1244 }
size_t len
Definition: 6502dis.c:15
#define mnem(n, mn)
bool(* parse_mnem_args)(char const *const *, ut16, ut8 **)
Definition: 8051_ass.c:278
static int get_arguments(char **arg, char const *arguments)
Definition: 8051_ass.c:189
static parse_mnem_args mnemonic(char const *user_asm, int *nargs)
Definition: 8051_ass.c:1162
static bool terminates_asm_line(char c)
Definition: 8051_ass.c:238
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, free(), get_arguments(), len, mnem, mnemonic(), rz_strbuf_set(), rz_strbuf_setbin(), and terminates_asm_line().