题意:
二进制指令转汇编指令,汇编指令转二进制指令。
思路:
额,条理分好,想全,思维不能乱。
代码:
int findyu(char yu[50],char c){ int l=strlen(yu); rep(i,0,l-1) if(c==yu[i]) return i;}int calc(char t[50],int x,int k){ int res=0; rep(i,x,x+k-1) res*=10, res+=(t[i]-'0'); return res;}int calc2(char t[50]){ int l=strlen(t); int res=0; rep(i,0,l-1) res*=2, res+=(t[i]-'0'); return res;}void print(int x){ int t1[10]; int c=0; rep(i,0,4){ t1[++c]=(x&1); x>>=1; } rep2(i,c,1) printf("%d",t1[i]);}int main(){ //freopen("test.in","r", stdin); int kind; mapmp1; mp1["ADD"]="000001"; mp1["SUB"]="000010"; mp1["DIV"]="000011"; mp1["MUL"]="000100"; mp1["MOVE"]="000101"; mp1["SET"]="000110"; map mp2; mp2["000001"]="ADD"; mp2["000010"]="SUB"; mp2["000011"]="DIV"; mp2["000100"]="MUL"; mp2["000101"]="MOVE"; mp2["000110"]="SET"; while(scanf("%d",&kind)!=EOF){ if(kind==1){ char ins[50],yu[50]; int ra,rb=0; scanf("%s%s",ins,yu); if(strcmp(ins,"SET")==0) ra=calc(yu,1,strlen(yu)-1); else{ int tc=findyu(yu,','); ra=calc(yu,1,tc-1); rb=calc(yu,tc+2,strlen(yu)-tc-2); } cout< 31){ cout<<"Error!"< 31 || rb<1 || rb>31){ cout<<"Error!"<