#include <cctype> 
#include <iostream> 
#include <map> 
#include <regex> 
#include <string> 
#include <vector> 
 
bool reg_match(const std::regex& r, const std::string& s, std::vector<std::string>& v) { 
   std::smatch m; 
   bool res = std::regex_search(s, m, r); 
   v.assign(m.begin( ), m.end( )); 
   return res; 
} 
 
std::string reg_replace(const std::regex& r, const std::string& s, const std::string& t) { 
   return std::regex_replace(s, r, t); 
} 
 
std::string a_minusculas(std::string s) { 
   for (char& c : s) { 
      c = std::tolower(c); 
   } 
   return s; 
} 
 
struct instruccion { 
   void* tipo; 
   int i, j, k; 
   int entero; 
   std::string etiqueta; 
}; 
 
auto bandera = std::regex_constants::icase; 
 
std::regex es_espacio(R"(\s+)", bandera); 
std::regex es_coma(R"(\s*,\s*)", bandera); 
std::regex es_corchete_izq(R"(\s*\[\s*)", bandera); 
std::regex es_corchete_der(R"(\s*\]\s*)", bandera); 
 
std::regex es_vacia(R"(^\s*$)", bandera); 
std::regex es_instruccion(R"(^\s*(([a-z_]\w*)\s*:)?\s*(.*?)\s*$)", bandera); 
 
 
std::regex es_nop(R"(^NOP$)", bandera); 
std::regex es_end(R"(^END$)", bandera); 
std::regex es_mov_imm(R"(^MOV r(\d), ([+-]?\d+)$)", bandera); 
std::regex es_mov_reg(R"(^MOV r(\d), r(\d)$)", bandera); 
std::regex es_get_dir_byte(R"(^GET r(\d), BYTE \[([+-]?\d+)\]$)", bandera); 
std::regex es_get_dir_word(R"(^GET r(\d), WORD \[([+-]?\d+)\]$)", bandera); 
std::regex es_get_ind_byte(R"(^GET r(\d), BYTE \[r(\d)\]$)", bandera); 
std::regex es_get_ind_word(R"(^GET r(\d), WORD \[r(\d)\]$)", bandera); 
std::regex es_put_dir_byte(R"(^PUT r(\d), BYTE \[([+-]?\d+)\]$)", bandera); 
std::regex es_put_dir_word(R"(^PUT r(\d), WORD \[([+-]?\d+)\]$)", bandera); 
std::regex es_put_ind_byte(R"(^PUT r(\d), BYTE \[r(\d)\]$)", bandera); 
std::regex es_put_ind_word(R"(^PUT r(\d), WORD \[r(\d)\]$)", bandera); 
std::regex es_add(R"(^ADD r(\d), r(\d), r(\d)$)", bandera); 
std::regex es_equ(R"(^EQU r(\d), r(\d), r(\d)$)", bandera); 
std::regex es_jmp(R"(^JMP ([a-z_]\w*)$)", bandera); 
std::regex es_jif(R"(^JIF r(\d), ([a-z_]\w*)$)", bandera); 
std::regex es_call(R"(^CALL ([a-z_]\w*)$)", bandera); 
std::regex es_ret(R"(^RET$)", bandera); 
std::regex es_push(R"(^PUSH r(\d)$)", bandera); 
std::regex es_pop(R"(^POP r(\d)$)", bandera); 
std::regex es_show_byte(R"(^SHOW BYTE r(\d)$)", bandera); 
std::regex es_show_word(R"(^SHOW WORD r(\d)$)", bandera); 
 
int main( ) { 
   std::vector<instruccion> instrucciones; 
   std::map<std::string, int> tabla_etiquetas; 
 
   std::string s; int num_inst = 0; 
   while (std::getline(std::cin, s)) { 
      auto pos = s.find('#'); 
      if (pos != std::string::npos) { 
         s.erase(pos); 
      } 
 
      s = a_minusculas(s); 
      s = reg_replace(es_espacio, s, " "); 
      s = reg_replace(es_coma, s, ", "); 
      s = reg_replace(es_corchete_izq, s, " ["); 
      s = reg_replace(es_corchete_der, s, "]"); 
 
      std::vector<std::string> matches; 
      if (reg_match(es_vacia, s, matches)) { 
         continue; 
      } else if (reg_match(es_instruccion, s, matches)) { 
         std::string etiqueta = matches[2]; 
         if (etiqueta != "") { 
            tabla_etiquetas[etiqueta] = num_inst; 
         } 
         s = matches[3]; 
 
         if (reg_match(es_nop, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&nop; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_end, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&end; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_mov_imm, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&mov_imm; 
            inst.i = std::stoi(matches[1]); 
            inst.entero = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_mov_reg, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&mov_reg; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_get_dir_byte, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&get_dir_byte; 
            inst.i = std::stoi(matches[1]); 
            inst.entero = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_get_dir_word, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&get_dir_word; 
            inst.i = std::stoi(matches[1]); 
            inst.entero = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_get_ind_byte, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&get_ind_byte; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_get_ind_word, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&get_ind_word; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_put_dir_byte, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&put_dir_byte; 
            inst.i = std::stoi(matches[1]); 
            inst.entero = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_put_dir_word, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&put_dir_word; 
            inst.i = std::stoi(matches[1]); 
            inst.entero = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_put_ind_byte, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&put_ind_byte; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_put_ind_word, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&put_ind_word; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_add, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&add; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            inst.k = std::stoi(matches[3]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_equ, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&equ; 
            inst.i = std::stoi(matches[1]); 
            inst.j = std::stoi(matches[2]); 
            inst.k = std::stoi(matches[3]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_jmp, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&jmp; 
            inst.etiqueta = matches[1]; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_jif, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&jif; 
            inst.i = std::stoi(matches[1]); 
            inst.etiqueta = matches[2]; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_call, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&call; 
            inst.etiqueta = matches[1]; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_ret, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&ret; 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_push, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&push; 
            inst.i = std::stoi(matches[1]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_pop, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&pop; 
            inst.i = std::stoi(matches[1]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_show_byte, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&show_byte; 
            inst.i = std::stoi(matches[1]); 
            instrucciones.push_back(inst); 
         } else if (reg_match(es_show_word, s, matches)) { 
            instruccion inst; 
            inst.tipo = &&show_word; 
            inst.i = std::stoi(matches[1]); 
            instrucciones.push_back(inst); 
         } 
 
         num_inst += 1; 
      } 
   } 
 
   static int r[10]; 
   static char memoria[16777216]; 
 
   int ip = 0; 
   std::vector<int> pila_ip; 
   std::vector<int> pila_datos; 
 
   for (;;) { 
      instruccion inst = instrucciones[ip++]; 
      goto *inst.tipo; 
 
      nop: { 
         continue; 
      } 
      end: { 
         return 0; 
      } 
      mov_imm: { 
         r[inst.i] = inst.entero; 
         continue; 
      } 
      mov_reg: { 
         r[inst.i] = r[inst.j]; 
         continue; 
      } 
      get_dir_byte: { 
         r[inst.i] = memoria[inst.entero]; 
         continue; 
      } 
      get_dir_word: { 
         r[inst.i] = *(int*)&memoria[inst.entero]; 
         continue; 
      } 
      get_ind_byte: { 
         r[inst.i] = memoria[r[inst.j]]; 
         continue; 
      } 
      get_ind_word: { 
         r[inst.i] = *(int*)&memoria[r[inst.j]]; 
         continue; 
      } 
      put_dir_byte: { 
         memoria[inst.entero] = r[inst.i]; 
         continue; 
      } 
      put_dir_word: { 
         *(int*)&memoria[inst.entero] = r[inst.i]; 
         continue; 
      } 
      put_ind_byte: { 
         memoria[r[inst.j]] = r[inst.i]; 
         continue; 
      } 
      put_ind_word: { 
         *(int*)&memoria[r[inst.j]] = r[inst.i]; 
         continue; 
      } 
      add: { 
         r[inst.i] = r[inst.j] + r[inst.k]; 
         continue; 
      } 
      equ: { 
         r[inst.i] = (r[inst.j] == r[inst.k]); 
         continue; 
      } 
      jmp: { 
         ip = tabla_etiquetas[inst.etiqueta]; 
         continue; 
      } 
      jif: { 
         if (r[inst.i] != 0) { 
            ip = tabla_etiquetas[inst.etiqueta]; 
         } 
         continue; 
      } 
      call: { 
         pila_ip.push_back(ip); 
         ip = tabla_etiquetas[inst.etiqueta]; 
         continue; 
      } 
      ret: { 
         ip = pila_ip.back( ); 
         pila_ip.pop_back( ); 
         continue; 
      } 
      push: { 
         pila_datos.push_back(r[inst.i]); 
         continue; 
      } 
      pop: { 
         r[inst.i] = pila_datos.back( ); 
         pila_datos.pop_back( ); 
         continue; 
      } 
      show_byte: { 
         printf("%c", r[inst.i]); 
         continue; 
      } 
      show_word: { 
         printf("%d", r[inst.i]); 
         continue; 
      } 
   } 
} 
