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

Go to the source code of this file.

Functions

static int i4004_get_ins_len (ut8 hex)
 
static int i4004dis (RzAsmOp *op, const ut8 *buf, int len)
 

Variables

static const int i4004_ins_len [16]
 
static const char * i4004_e [16]
 
static const char * i4004_f [16]
 

Function Documentation

◆ i4004_get_ins_len()

static int i4004_get_ins_len ( ut8  hex)
static

Definition at line 53 of file i4004dis.c.

53  {
54  ut8 high = (hex & 0xf0) >> 4;
55  int ret = i4004_ins_len[high];
56  if (ret == 3)
57  ret = (hex & 1) ? 1 : 2;
58  return ret;
59 }
static const int i4004_ins_len[16]
Definition: i4004dis.c:11
uint8_t ut8
Definition: lh5801.h:11
static const char hex[16]
Definition: print.c:21

References hex, and i4004_ins_len.

Referenced by i4004dis().

◆ i4004dis()

static int i4004dis ( RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 61 of file i4004dis.c.

61  {
62  int rlen = i4004_get_ins_len(*buf);
63  ut8 high = (*buf & 0xf0) >> 4;
64  ut8 low = (*buf & 0xf);
65  const char *buf_asm = "invalid";
66  if (rlen > len) {
67  return op->size = 0;
68  }
69  switch (high) {
70  case 0: buf_asm = low ? "invalid" : "nop"; break;
71  case 1: buf_asm = sdb_fmt("jcn %d 0x%02x", low, buf[1]); break;
72  case 2:
73  if (rlen == 1) {
74  buf_asm = sdb_fmt("src r%d", (low & 0xe));
75  } else {
76  buf_asm = sdb_fmt("fim r%d, 0x%02x", (low & 0xe), buf[1]);
77  }
78  break;
79  case 3:
80  if ((low & 1) == 1) {
81  buf_asm = sdb_fmt("jin r%d", (low & 0xe));
82  } else {
83  buf_asm = sdb_fmt("fin r%d", (low & 0xe));
84  }
85  break;
86  case 4: buf_asm = sdb_fmt("jun 0x%03x", ((ut16)(low << 8) | buf[1])); break;
87  case 5: buf_asm = sdb_fmt("jms 0x%03x", ((ut16)(low << 8) | buf[1])); break;
88  case 6: buf_asm = sdb_fmt("inc r%d", low); break;
89  case 7: buf_asm = sdb_fmt("isz r%d, 0x%02x", low, buf[1]); break;
90  case 8: buf_asm = sdb_fmt("add r%d", low); break;
91  case 9: buf_asm = sdb_fmt("sub r%d", low); break;
92  case 10: buf_asm = sdb_fmt("ld r%d", low); break;
93  case 11: buf_asm = sdb_fmt("xch r%d", low); break;
94  case 12: buf_asm = sdb_fmt("bbl %d", low); break;
95  case 13: buf_asm = sdb_fmt("ldm %d", low); break;
96  case 14: buf_asm = i4004_e[low]; break;
97  case 15: buf_asm = i4004_f[low]; break;
98  }
99  rz_strbuf_set(&op->buf_asm, buf_asm);
100  return op->size = rlen;
101 }
size_t len
Definition: 6502dis.c:15
uint16_t ut16
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
static const char * i4004_f[16]
Definition: i4004dis.c:34
static int i4004_get_ins_len(ut8 hex)
Definition: i4004dis.c:53
static const char * i4004_e[16]
Definition: i4004dis.c:15
voidpf void * buf
Definition: ioapi.h:138
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
Definition: dis.c:32

References i4004_e, i4004_f, i4004_get_ins_len(), len, rz_strbuf_set(), and sdb_fmt().

Referenced by disassemble().

Variable Documentation

◆ i4004_e

const char* i4004_e[16]
static
Initial value:
= {
"wrm",
"wmp",
"wrr",
"wpm",
"wr0",
"wr1",
"wr2",
"wr3",
"sbm",
"rdm",
"rdr",
"adm",
"rd0",
"rd1",
"rd2",
"rd3"
}

Definition at line 15 of file i4004dis.c.

Referenced by i4004dis().

◆ i4004_f

const char* i4004_f[16]
static
Initial value:
= {
"clb",
"clc",
"iac",
"cmc",
"cma",
"ral",
"rar",
"tcc",
"dac",
"tcs",
"stc",
"daa",
"kbp",
"dcl",
"invalid",
"invalid"
}

Definition at line 34 of file i4004dis.c.

Referenced by i4004dis().

◆ i4004_ins_len

const int i4004_ins_len[16]
static
Initial value:
= {
1, 2, 3, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1
}

Definition at line 11 of file i4004dis.c.

Referenced by i4004_get_ins_len().