Rizin
unix-like reverse engineering framework and cli tools
i8080dis.c File Reference
#include <string.h>
#include <stdio.h>
#include <assert.h>

Go to the source code of this file.

Classes

struct  arg_t
 
struct  opcode_t
 

Functions

static void arg (char *s, int const cmd, struct arg_t const *arg, int val)
 
static int i8080_disasm (unsigned char const *const code, char *text, int text_sz)
 

Variables

static char * reg [] = { "b", "c", "d", "e", "h", "l", "m", "a" }
 
static char * rp [] = { "b", "d", "h", "sp" }
 
static char * push_rp [] = { "b", "d", "h", "psw" }
 
static char * cond [] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" }
 
static char * rst [] = { "0", "1", "2", "3", "4", "5", "6", "7" }
 
static struct opcode_t opcodes []
 

Function Documentation

◆ arg()

static void arg ( char *  s,
int const  cmd,
struct arg_t const arg,
int  val 
)
static

Definition at line 115 of file i8080dis.c.

115  {
116  if (arg->type == 3) {
117  strcat(s, arg->fmt[(cmd >> arg->shift) & arg->mask]);
118  } else {
119  if (arg->type == 1)
120  sprintf(s, "%02X", val & 0xff);
121  else if (arg->type == 2)
122  sprintf(s, "%04X", val);
123  }
124 }
ut16 val
Definition: armass64_const.h:6
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
sprintf
Definition: kernel.h:365
static RzSocket * s
Definition: rtr.c:28

References cmd, s, sprintf, and val.

Referenced by i8080_disasm().

◆ i8080_disasm()

static int i8080_disasm ( unsigned char const *const  code,
char *  text,
int  text_sz 
)
static

Definition at line 126 of file i8080dis.c.

126  {
127  int const cmd = code[0];
128  int const p = code[1] | (code[2] << 8);
129 
130  struct opcode_t const *op;
131  for (op = &opcodes[0]; op->size; ++op) {
132  int const grp = cmd &
133  ~((op->arg1.mask << op->arg1.shift) |
134  (op->arg2.mask << op->arg2.shift));
135  int const branch = (grp == 0xc0 || grp == 0xc2 || grp == 0xc4);
136  if (grp == op->cmd) {
137  strcpy(text, op->name);
138  if (!branch) strcat(text, " ");
139  arg(text + strlen(text), cmd, &op->arg1, p);
140  if (op->arg2.type != 0) strcat(text, (branch ? " " : ", "));
141  arg(text + strlen(text), cmd, &op->arg2, p);
142  return op->size;
143  }
144  }
145  snprintf(text, text_sz, "db @ 0x%02x", cmd);
146  return 1;
147 }
ut8 op
Definition: 6502dis.c:13
static void arg(char *s, int const cmd, struct arg_t const *arg, int val)
Definition: i8080dis.c:115
static struct opcode_t opcodes[]
snprintf
Definition: kernel.h:364
void * p
Definition: libc.cpp:67
#define const
Definition: ansidecl.h:240
Definition: inftree9.h:24
Definition: dis.c:32

References arg(), test-lz4-speed::branch, cmd, const, op, opcodes, p, snprintf, and create_tags_rz::text.

Variable Documentation

◆ cond

char* cond[] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" }
static

Definition at line 38 of file i8080dis.c.

◆ opcodes

struct opcode_t opcodes[]
static

Referenced by i8080_disasm().

◆ push_rp

char* push_rp[] = { "b", "d", "h", "psw" }
static

Definition at line 37 of file i8080dis.c.

◆ reg

char* reg[] = { "b", "c", "d", "e", "h", "l", "m", "a" }
static

Definition at line 35 of file i8080dis.c.

◆ rp

◆ rst

char* rst[] = { "0", "1", "2", "3", "4", "5", "6", "7" }
static

Definition at line 39 of file i8080dis.c.