#include "stdio.h"
typedef unsigned char uint8;
void showBinary(const char* name, int c)
{
char res[32] = {};
char* p = &res[31];
for (int i = 8; i--; c >>= 1){
*--p = (c & 1) + '0';
}
printf("%s = %s", name, p);
}
int opcode(uint8 op, uint8 data[], uint8 mem[])
{
switch (op)
{
case 0x40u:
case 0x44u: mem[data[0]] = data[1]; return 0; // 写入
case 0x4au: data[0] = mem[data[0]]; showBinary("read", data[0]); return 1; //读取
case 0x88u: data[0] = data[0] + data[1]; showBinary("add", data[0]); return 1; //加法
}
return 1;
}
int opcodeParser(const char* p, uint8 data[])
{
int a;
for (a = 0; *p; ++p){
if (*p == ' '){ ++p; break; }
a = (a << 1) | (*p - '0');
}
data[0] = (uint8)a;
if (*p == 0) return 1u;
for (a = 0; *p; ++p){
if (*p == ' '){ ++p; break; }
a = (a << 1) | (*p - '0');
}
data[1] = (uint8)a;
if (*p == 0) return 2u;
for (a = 0; *p; ++p){
if (*p == ' '){ ++p; break; }
a = (a << 1) | (*p - '0');
}
data[2] = (uint8)a;
if (*p == 0) return 3u;
}
int main()
{
uint8 mem[256] = { 0 };
mem[0] = 0x40u;
mem[1] = 0x88u;
mem[2] = 0x4au;
mem[0x10] = 0x1u;
mem[0x11] = 0x2u;
mem[0x12] = 0x3u;
int cnt = 0;
scanf("%d", &cnt);
char ss[64] = {};
gets(ss);
int cmd = 0;
for (int i = cnt; i--;){
gets(ss);
uint8 data[8] = {};
opcodeParser(ss, data);
cmd += opcode(mem[data[0]], data + 1, mem);
}
return 0;
}