#include<stdio.h> #include<stdlib.h> #include<string.h> char code[257];/*指令*/ int pc;/*Program counter*/ int reg_a;/*寄存器a*/ int reg_b;/*寄存器b*/ int hex2dec(hex,length) char*hex;//十六进制数
int length;//长度
{ int res = 0; int i; for(i=0;i<length;i++){
res *= 16; if(isdigit(hex[i])){
res +=hex[i]-'0'; } else{
res +=hex[i]-'A'+ 10; } } return res; } void
dec2hex(h,a) int h; char*a; { if(h<10)*a = h+'0'; else*a =(h-10)+'A'; } void
interpreter() { int t; int end = 1;
pc = 0;
reg_a = 0;
reg_b = 0; while(end){ switch(code[pc]){ case'0':
reg_a = hex2dec(code+hex2dec(code+pc+1,2),1);
pc += 3; break; case'1':
dec2hex(reg_a,code+hex2dec(code+pc+1,2));
pc += 3; break; case'2':
t = reg_a;
reg_a = reg_b;
reg_b = t;
pc++; break; case'3':
t = reg_a + reg_b;
reg_a = t&0xf;
reg_b =((t&0xf0)>>4);
pc++; break; case'4':
reg_a++;
reg_a = reg_a&0xf;
pc++; break; case'5':
reg_a--; if(reg_a<0) reg_a += 16;
pc++; break; case'6': if(reg_a) pc+=3; else{
pc = hex2dec(code+pc+1,2); } break; case'7':
pc = hex2dec(code + pc + 1,2); break; case'8':
end = 0; break; } } } int main(){ int i; while(scanf("%s",code)!=-1){ if(code[0]=='8')break;
interpreter(); for(i=0;i<256;i++){ if(code[i])putchar(code[i]); elseputchar('0'); } putchar('\n'); } return 0; }