void decodeInstruction(instruction_t instruction,uint32_t *registro,flags_t *bandera, uint8_t *SRAM, uint16_t *codificacion, char **Flash) { int i; *codificacion=0; // valor incial // comparar el mnemonic con el nombre de cada una de las funciones, y asi ejecutar la adecuada if( strcmp(instruction.mnemonic,"LDR") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(13<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; instruction.op3_value<<=2; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { LDR(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read); } } if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#')) { *codificacion=(19<<11)+(instruction.op1_value<<8)+instruction.op3_value; instruction.op3_value<<=2; if(((*(registro+13)+instruction.op3_value)>=0x20000000)&&((*(registro+13)+instruction.op3_value)<0x40000000)) { LDR(registro+instruction.op1_value,*(registro+13),instruction.op3_value,SRAM); } if((*(registro+13)+instruction.op3_value)<0x20000000) { } if((*(registro+13)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+13)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read); } } if((instruction.op1_type=='R') && (instruction.op2_type=='P') && (instruction.op3_type=='#')) // label { *codificacion=(9<<11)+(instruction.op1_value<<8)+instruction.op3_value; instruction.op3_value<<=2; if(((*(registro+15)+instruction.op3_value)>=0x20000000)&&((*(registro+15)+instruction.op3_value)<0x40000000)) { LDR(registro+instruction.op1_value,*(registro+15),instruction.op3_value,SRAM); } if((*(registro+15)+instruction.op3_value)<0x20000000) { } if((*(registro+15)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+15)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read); } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(11<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { LDR(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read); } } registro[15]++; } if( strcmp(instruction.mnemonic,"LDRB") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(15<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { LDRB(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { uint8_t data; IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,&data,Read); *(registro+instruction.op1_value)= (uint32_t)data; } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(1<<14)+(7<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { LDRB(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { uint8_t data; IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,&data,Read); *(registro+instruction.op1_value)=(uint32_t) data; } } registro[15]++; } if( strcmp(instruction.mnemonic,"LDRH") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(1<<15)+(1<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; instruction.op3_value<<=1; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { LDRH(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read); } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(5<<12)+(5<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { LDRH(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read); } registro[15]++; } if( strcmp(instruction.mnemonic,"LDRSB") ==0) { *codificacion=(5<<12)+(3<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { LDRSB(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read); } registro[15]++; } if( strcmp(instruction.mnemonic,"LDRSH") ==0) { *codificacion=(5<<12)+(7<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { LDRSH(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read); } registro[15]++; } if( strcmp(instruction.mnemonic,"STR") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(3<<13)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; instruction.op3_value<<=2; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { STR(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write); } } if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#')) { *codificacion=(9<<12)+(instruction.op1_value<<8)+instruction.op3_type; instruction.op3_value<<=2; if(((*(registro+13)+instruction.op3_value)>=0x20000000)&&((*(registro+13)+instruction.op3_value)<0x40000000)) { STR(*(registro+instruction.op1_value),*(registro+13),instruction.op3_value,SRAM); } if((*(registro+13)+instruction.op3_value)<0x20000000) { } if((*(registro+13)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+13)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write); } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(5<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { STR(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Write); } } registro[15]++; } if( strcmp(instruction.mnemonic,"STRB") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(7<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { STRB(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { uint8_t data; data=(uint8_t)(*(registro+instruction.op1_value)); IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,&data,Write); } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(21<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { STRB(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { uint8_t data; data=(uint8_t)(*(registro+instruction.op1_value)); IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,&data,Write); } } registro[15]++; } if( strcmp(instruction.mnemonic,"STRH") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { *codificacion=(1<<15)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; instruction.op3_value<<=1; if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000)) { STRH(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM); } if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000) { } if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write); } } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { *codificacion=(5<<12)+(1<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000)) { STRH(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM); } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000) { } if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000) { //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Write); } } registro[15]++; } if( strcmp(instruction.mnemonic,"PUSH") ==0) { for(i=0;i<8;i++) { *codificacion+=(instruction.registers_list[i]<<i); } *codificacion+=(11<<12)+(1<<10)+(instruction.registers_list[14]<<8); PUSH(registro,SRAM,&instruction.registers_list[0]); registro[15]++; } if( strcmp(instruction.mnemonic,"POP") ==0) { for(i=0;i<8;i++) { *codificacion+=(instruction.registers_list[i]<<i); } *codificacion=(11<<12)+(3<<10)+(instruction.registers_list[15]<<8); POP(registro,SRAM,&instruction.registers_list[0]); registro[15]++; } if( strcmp(instruction.mnemonic,"ADCS") ==0) { *codificacion=(1<<14)+(5<<6)+(instruction.op2_value<<3)+instruction.op1_value; ADCS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"ADD") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { ADD(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value)); *codificacion=(1<<14)+(1<<10)+(instruction.op2_value<<3)+((8&instruction.op1_value)<<4)+(7&instruction.op1_value); } if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#')) { ADD(registro+instruction.op1_value,*(registro+13),instruction.op2_value); *codificacion=(21<<11)+(instruction.op1_value<<8)+instruction.op3_value; } if((instruction.op1_type=='S') && (instruction.op2_type=='S') && (instruction.op3_type=='#')) { ADD(registro+13,*(registro+13),instruction.op3_value); *codificacion=(11<<12)+instruction.op3_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='R')) { ADD(registro+instruction.op1_value,*(registro+13),*(registro+instruction.op3_value)); *codificacion=(1<<14)+(1<<10)+(13<<3)+((8&instruction.op1_value)<<4)+(7&instruction.op1_value); } if((instruction.op1_type=='S') && (instruction.op2_type=='R')) { ADD(registro+13,*(registro+13),*(registro+instruction.op2_value)); *codificacion=(1<<14)+(9<<7)+5+(instruction.op2_value<<3); } registro[15]++; } if( strcmp(instruction.mnemonic,"ADDS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { ADDS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera); *codificacion=(7<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='#')) { ADDS(registro+instruction.op1_value,*(registro+instruction.op1_value),instruction.op2_value,bandera); *codificacion=(3<<12)+(instruction.op1_value<<8)+instruction.op2_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { ADDS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera); *codificacion=(3<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } // los parametros de las demas funciones aritmeticas, de desplazamiento y logicas son similares if( strcmp(instruction.mnemonic,"ANDS") ==0) { *codificacion=(1<<14)+(instruction.op2_value<<3)+instruction.op1_value; ANDS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"ASRS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { ASRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); *codificacion=(1<<14)+(1<<8)+(instruction.op2_value<<3)+instruction.op1_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { ASRS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera); *codificacion=(1<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"BICS") ==0) { *codificacion=(1<<14)+(14<<6)+(instruction.op2_value<<3)+instruction.op1_value; BICS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"CMN") ==0) { *codificacion=(1<<14)+(11<6)+(instruction.op2_value<<3)+instruction.op1_value; CMN(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); // En diferencia a las demas funciones, se envian como parametros 2 valores registro[15]++; } if( strcmp(instruction.mnemonic,"CMP") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { if(instruction.op1_value>=8) { CMP(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); // En diferencia a las demas funciones, se envian como parametros 2 valores *codificacion=(1<<14)+(5<<8)+(instruction.op2_value<<3)+(7&instruction.op1_value)+((8&instruction.op1_value)<<4); } else { CMP(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); // En diferencia a las demas funciones, se envian como parametros 2 valores *codificacion=(1<<14)+(10<<6)+(instruction.op2_value<<3)+instruction.op1_value; } } if((instruction.op1_type=='R') && (instruction.op2_type=='#')) { CMP(*(registro+instruction.op1_value),instruction.op2_value, bandera); // Como parametros se tienen el contenido de un registro y un valor *codificacion=(5<<11)+(instruction.op1_value<<8)+instruction.op2_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"EORS") ==0) { *codificacion=(1<<14)+(1<<6)+(instruction.op2_value<<3)+instruction.op1_value; EORS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value),bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"LSLS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { LSLS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); *codificacion=(1<<14)+(1<<7)+(instruction.op2_value<<3)+instruction.op1_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { LSLS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera); *codificacion=(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"LSRS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { LSRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); *codificacion=(1<<14)+(3<<6)+(instruction.op2_value<<3)+instruction.op1_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { LSRS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera); *codificacion=(1<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"MOV") ==0) { *codificacion=(1<<14)+(3<<9)+(instruction.op2_value<<3)+(7&instruction.op1_value)+((8&instruction.op1_value)<<4); MOV(registro+instruction.op1_value,*(registro+instruction.op2_value)); // Envio como parametros una direccion y el contenido de un registro registro[15]++; } if( strcmp(instruction.mnemonic,"MOVS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='#')) { MOVS(registro+instruction.op1_value,instruction.op2_value, bandera); *codificacion=(1<<13)+(instruction.op1_value<<8)+instruction.op2_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R')) { MOVS(registro+instruction.op1_value,*(registro+instruction.op2_value),bandera); *codificacion=(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"MULS") ==0) { *codificacion=(1<<14)+(13<<6)+(instruction.op2_value<<3)+instruction.op3_value; MULS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"MVNS") ==0) { *codificacion=(1<<14)+(15<<6)+(instruction.op2_value<<3)+instruction.op1_value; RSBS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"NOP") ==0) { *codificacion=(11<<12)+(15<<8); registro[15]++; } if( strcmp(instruction.mnemonic,"ORRS") ==0) { *codificacion=(1<<14)+(3<<8)+(instruction.op2_value<<3)+instruction.op1_value; ORRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"REV") ==0) { *codificacion=(11<<12)+(5<<9)+(instruction.op2_value<<3)+instruction.op1_value; REV(registro+instruction.op1_value, *(registro+instruction.op2_value)); registro[15]++; } if( strcmp(instruction.mnemonic,"REV16") ==0) { *codificacion=(11<<12)+(5<<9)+(1<<6)+(instruction.op2_value<<3)+instruction.op1_value; REV16(registro+instruction.op1_value,*(registro+instruction.op2_value)); registro[15]++; } if( strcmp(instruction.mnemonic,"REVSH") ==0) { *codificacion=(11<<12)+(5<<9)+(3<<6)+(instruction.op2_value<<3)+instruction.op1_value; REVSH(registro+instruction.op1_value,*(registro+instruction.op2_value)); registro[15]++; } if( strcmp(instruction.mnemonic,"RORS") ==0) { *codificacion=(1<<14)+(7<<6)+(instruction.op2_value<<3)+instruction.op1_value; RORS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"RSBS") ==0) { *codificacion=(1<<14)+(9<<6)+(instruction.op2_value<<3)+instruction.op1_value; RSBS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"SBCS") ==0) { *codificacion=(1<<14)+(3<<7)+(instruction.op2_value<<3)+instruction.op1_value; SBCS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); registro[15]++; } if( strcmp(instruction.mnemonic,"SUB") ==0) { if((instruction.op1_type=='S') && (instruction.op2_type=='S') && (instruction.op3_type=='#')) { SUB(registro+13,*(registro+13),instruction.op3_value); *codificacion=(11<<12)+(1<<7)+instruction.op3_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"SUBS") ==0) { if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#')) { SUBS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera); *codificacion=(15<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='#')) { SUBS(registro+instruction.op1_value,*(registro+instruction.op1_value),instruction.op2_value,bandera); *codificacion=(7<<11)+(instruction.op1_value<<8)+instruction.op2_value; } if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R')) { SUBS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera); *codificacion=(13<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value; } registro[15]++; } if( strcmp(instruction.mnemonic,"TST") ==0) { *codificacion=(1<<14)+(1<<9)+(instruction.op2_value<<3)+instruction.op1_value; TST(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); // Como parametros se tienen el contenido de un registro y un valor registro[15]++; } // Las siguientes funciones, son funciones de saltos if( strcmp(instruction.mnemonic,"B") ==0) { *codificacion=(7<<13)+instruction.op1_value; B(registro,instruction.op1_value); // Envio como parametroa la direccion de registro y el valor del salto } if( strcmp(instruction.mnemonic,"BL") ==0) { *codificacion=(31<<11)+(2047&instruction.op1_value); BL(registro,instruction.op1_value); // Envio como parametroa la direccion de registro y el valor del salto } if( strcmp(instruction.mnemonic,"BLX") ==0) { *codificacion=(1<<14)+(15<<7)+(instruction.op1_value<<3); BLX(registro,*(registro+instruction.op1_value)); // Envio como parametroa la direccion de registro y el contenido de un registro } if( strcmp(instruction.mnemonic,"BX") ==0) { *codificacion=(1<<14)+(14<<7)+(instruction.op1_value<<3); if(instruction.op1_type=='L') // Sucede cuando { BX(registro,registro[14]); // PC=LR } if(instruction.op1_type=='R') // Sucede cuando se tiene como parametro un registro diferente a LR { BX(registro,*(registro+instruction.op1_value)); } } if( strcmp(instruction.mnemonic,"BEQ") ==0) { *codificacion=(13<<12)+instruction.op1_value; BEQ(registro,instruction.op1_value,*bandera); // Envio como parametros la direccion de registro, el valor del salto y las banderas } // Todas las siguientes funciones de salto tienen los mismos parametro que BEQ if( strcmp(instruction.mnemonic,"BNE") ==0) { *codificacion=(13<<12)+(1<<8)+instruction.op1_value; BNE(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BCS") ==0) { *codificacion=(13<<12)+(2<<8)+instruction.op1_value; BCS(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BCC") ==0) { *codificacion=(13<<12)+(3<<8)+instruction.op1_value; BCC(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BMI") ==0) { *codificacion=(13<<12)+(4<<8)+instruction.op1_value; BMI(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BPL") ==0) { *codificacion=(13<<12)+(5<<8)+instruction.op1_value; BPL(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BVS") ==0) { *codificacion=(13<<12)+(6<<8)+instruction.op1_value; BVS(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BVC") ==0) { *codificacion=(13<<12)+(7<<8)+instruction.op1_value; BVC(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BHI") ==0) { *codificacion=(13<<12)+(8<<8)+instruction.op1_value; BHI(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BLS") ==0) { *codificacion=(13<<12)+(9<<8)+instruction.op1_value; BLS(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BGE") ==0) { *codificacion=(13<<12)+(10<<8)+instruction.op1_value; BGE(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BLT") ==0) { *codificacion=(13<<12)+(11<<8)+instruction.op1_value; BLT(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BGT") ==0) { *codificacion=(13<<12)+(12<<8)+instruction.op1_value; BGT(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BLE") ==0) { *codificacion=(13<<12)+(13<<8)+instruction.op1_value; BLE(registro,instruction.op1_value,*bandera); } if( strcmp(instruction.mnemonic,"BAL") ==0) { *codificacion=(13<<12)+(14<<8)+instruction.op1_value; BAL(registro,instruction.op1_value,*bandera); } }
int main() { int op; uint32_t registro[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; char banderas[4]; do{ system("cls"); printf("seleccione la opcion 1 para mostrar los valores de los registros\n"); printf("seleccione la opcion 2 para sumar registros \n"); printf("seleccione la opcion 3 para multiplicacion logica (AND) de registros \n"); printf("seleccione la opcion 4 para Eor a nivel de bits \n"); printf("seleccione la opcion 5 para desplazar de un registro a otro \n"); printf("seleccione la opcion 6 para suma logica (OR) de registro\n"); printf("seleccione la opcion 7 para ADN sin almacenar, solo modifica banderas \n"); printf("seleccione la opcion 8 para comparar (SUB sin almacenar), solo modifica banderas\n"); printf("seleccione la opcion 9 Multiplicacion de registros, solo se alacenan 32 bits menos significativos\n"); printf("seleccione la opcion 10 AND sin almacenacmiento, solo modifica banderas\n"); printf("seleccione la opcion 11 para LSL desplazamiento logico a la izquierda \n"); printf("seleccione la opcion 12 para LSR desplazamiento logico a la derecha \n"); printf("seleccione la opcion 13 para ROR rotacion a la derecha \n"); printf("seleccione la opcion 14 para ASR desplazamiento aritmetico a la derecha \n"); printf("seleccione la opcion 15 para BIC Realiza una AND de un registro con otro negado \n"); printf("seleccione la opcion 16 para MUN guarda en un registro la negacion de otro\n"); printf("seleccione la opcion 17 para RSB niega un valor de registro\n"); printf("seleccione la opcion 18 para NOP da un retardo de un ciclo de reloj (no hace nada) \n"); printf("seleccione la opcion 19 para REV toma grupos de 8 bits y los desplaza \n"); printf("seleccione la opcion 20 para REVIG toma grupos de 16 bits y los agrupa en grupos de dos bytes\n"); printf("seleccione la opcion 21 para REVSH extencion con signo\n\n"); scanf("%d",&op); system("cls"); switch(op){ case 1: //mostrar_valores(registro); break; case 2: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); ADD(registro,®istro[0],registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 3: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); AND(registro,®istro[0],registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 4: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); EOR(registro,®istro[0],registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 5: printf("ingrese el valor del registro origen:\n"); scanf("%d",®istro[1]); MOV(registro,®istro[0],registro[1],banderas); printf("%d valor del resultado \n",registro[0]); break; case 7: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); CMN(registro,registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 8: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); CMP(registro,registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 9: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); MUL(registro,®istro[0],registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 10: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[2]); TST(registro,registro[1],registro[2],&banderas[0]); printf("%d valor del resultado \n",registro[0]); printf("%d valor del resultado bandera n \n",banderas[N]); printf("%d valor del resultado bandera z \n",banderas[Z]); printf("%d valor del resultado bandera c \n",banderas[C]); printf("%d valor del resultado bandera v \n",banderas[V]); break; case 11: printf("ingrese el valor del registro:\n"); scanf("%d",®istro[1]); printf("ingrese el numero de desplazamientos:\n"); scanf("%d",®istro[2]); LSL(registro,®istro[0],registro[1],registro[2],banderas); printf("%d valor del resultado \n",registro[0]); break; case 12: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese elnumero de desplazamientos:\n"); scanf("%d",®istro[2]); LSR(registro,®istro[0],registro[1],registro[2],banderas); printf("%d valor del resultado \n",registro[0]); break; case 13: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese elnumero de desplazamientos:\n"); scanf("%d",®istro[2]); ROR(registro,®istro[0],registro[1],registro[2],banderas); printf("%d valor del resultado \n",registro[0]); break; case 14: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[1]); printf("ingrese elnumero de desplazamientos:\n"); scanf("%d",®istro[2]); ASR(registro,®istro[0],registro[1],registro[2],banderas); printf("%d valor del resultado \n",registro[0]); break; case 15: printf("ingrese el valor del primer registro:\n"); scanf("%d",®istro[0]); printf("ingrese el valor del segundo registro:\n"); scanf("%d",®istro[1]); BIC(registro,®istro[0],registro[1],banderas); printf("%d valor del resultado \n",registro[0]); break; case 16: printf("ingrese un valor del registro origen\n"); scanf("%d",®istro[1]); MVN(registro,®istro[0],registro[1],banderas); printf("%d valor del resultado \n",registro[0]); break; case 17: printf("ingrese un valor de registro\n"); scanf("%d",®istro[1]); RSB(registro,®istro[0],registro[1],0,banderas); printf("%d valor del resultado \n",registro[0]); break; case 18: NOP(registro); break; case 19: printf("ingrese un valor de registro \n"); scanf("%d",®istro[0]); REV(registro,®istro[0]); printf("%d valor del resultado \n",registro[0]); break; case 20: printf("ingrese un valor de registro \n"); scanf("%d",®istro[0]); REVIG(registro,®istro[0]); printf("%d valor del resultado \n",registro[0]); break; case 21: printf("ingrese un valor de registro \n"); scanf("%d",®istro[0]); REVSH(registro,®istro[0]); printf("%d valor del resultado \n",registro[0]); break; default: printf("Opcion invalida\n\n"); break; } printf("\nDesea realizar otra operacion?\n<1>-si\n<0>-no\n"); scanf("%d",&op); system("cls"); }while(op); return 0; }
void decodeInstruction(instruction_t instruction, uint32_t *dir_reg, char *dir_flags, uint8_t *SRAM, uint16_t *dec) { uint8_t *R_activos=instruction.registers_list; /* Comparacion de mnemonic y Llamado de las funciones */ if( strcmp(instruction.mnemonic,"ADC") == 0 || strcmp(instruction.mnemonic,"ADCS") == 0){ dir_reg[PC]++; *dec=16704; *dec=*dec|instruction.op3_value<<3|instruction.op1_value; dir_reg[instruction.op1_value]=ADC(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); } if( strcmp(instruction.mnemonic,"ADDS") == 0 || strcmp(instruction.mnemonic,"ADD") == 0){ dir_reg[PC]++; if(instruction.op2_type=='S'){ *dec=45056; dir_reg[SP]=ADD(dir_reg[SP],instruction.op3_value,dir_flags); *dec=*dec|instruction.op3_value;} else if(instruction.op3_type=='#'){ *dec=7168; *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; dir_reg[instruction.op1_value]=ADD(dir_reg[instruction.op2_value], instruction.op3_value,dir_flags); mvprintw(4,20,"%X",*dec);} else{ *dec=6144; *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; dir_reg[instruction.op1_value]=ADD(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);} } if( strcmp(instruction.mnemonic,"AND") == 0 || strcmp(instruction.mnemonic,"ANDS") == 0){ dir_reg[PC]++; *dec=16384; if(instruction.op3_type=='#'){ dir_reg[instruction.op1_value]=AND(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);} else dir_reg[instruction.op1_value]=AND(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); } if( strcmp(instruction.mnemonic,"ASR") == 0 || strcmp(instruction.mnemonic,"ASRS") == 0){ dir_reg[PC]++; if(instruction.op3_type=='#'){ *dec=4096; *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; dir_reg[instruction.op1_value]=ASR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);} else{ *dec=16640; *dec=*dec|instruction.op3_value<<3|instruction.op1_value; dir_reg[instruction.op1_value]=ASR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);} } if( strcmp(instruction.mnemonic,"BICS") == 0 || strcmp(instruction.mnemonic,"BICS") == 0){ dir_reg[PC]++; if(instruction.op3_type=='#') dir_reg[instruction.op1_value]=BIC(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags); else{ *dec=17280; dir_reg[instruction.op1_value]=BIC(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"CMN" ) == 0 || strcmp(instruction.mnemonic,"CMNS") == 0){ dir_reg[PC]++; CMN(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value],dir_flags); *dec=17088; *dec=*dec|instruction.op2_value<<3|instruction.op1_value; mvprintw(4,20,"%X",*dec); } if( strcmp(instruction.mnemonic,"CMP") == 0 || strcmp(instruction.mnemonic,"CMPS") == 0){ dir_reg[PC]++; CMP(dir_reg[instruction.op1_value],dir_reg[instruction.op2_value],dir_flags); *dec=17024; *dec=*dec|instruction.op2_value<<3|instruction.op1_value; mvprintw(4,20,"%X",*dec); } if( strcmp(instruction.mnemonic,"EOR") == 0 || strcmp(instruction.mnemonic,"EORS") == 0){ dir_reg[PC]++; *dec=16448; if(instruction.op3_type=='#') dir_reg[instruction.op1_value]=EOR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags); else dir_reg[instruction.op1_value]=EOR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); } if( strcmp(instruction.mnemonic,"LSLS") == 0 || strcmp(instruction.mnemonic,"LSL") == 0){ dir_reg[PC]++; if(instruction.op3_type=='#'){ *dec=0; dir_reg[instruction.op1_value]=LSL(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=16512; dir_reg[instruction.op1_value]=LSL(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"LSRS") == 0 || strcmp(instruction.mnemonic,"LSR") == 0){ dir_reg[PC]++; if(instruction.op3_type=='#'){ *dec=2048; dir_reg[instruction.op1_value]=LSR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=16576; dir_reg[instruction.op1_value]=LSR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"MOV") == 0 || strcmp(instruction.mnemonic,"MOVS") == 0){ dir_reg[PC]++; if(instruction.op2_type=='#'){ *dec=8192; dir_reg[instruction.op1_value]=MOV(instruction.op2_value,dir_flags); *dec=*dec|instruction.op1_value<<8|instruction.op2_value;} else{ *dec=0; dir_reg[instruction.op1_value]=MOV(dir_reg[instruction.op2_value],dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"MUL") == 0 || strcmp(instruction.mnemonic,"MULS") == 0){ dir_reg[PC]++; *dec=17216; if(instruction.op3_type=='#'){ dir_reg[instruction.op1_value]=MUL(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);} else{ dir_reg[instruction.op1_value]=MUL(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"MVN") == 0 || strcmp(instruction.mnemonic,"MVNS") == 0){ dir_reg[PC]++; *dec=17344; dir_reg[instruction.op1_value]=MVN(dir_reg[instruction.op2_value], dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"ORR") == 0 || strcmp(instruction.mnemonic,"ORRS") == 0){ dir_reg[PC]++; *dec=17152; if(instruction.op3_type=='#'){ dir_reg[instruction.op1_value]=ORR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);} else{ dir_reg[instruction.op1_value]=ORR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"REV") == 0 || strcmp(instruction.mnemonic,"REVS") == 0){ dir_reg[PC]++; *dec=47616; dir_reg[instruction.op1_value]=REV(dir_reg[instruction.op2_value]); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"REVG") == 0 || strcmp(instruction.mnemonic,"REVGS") == 0){ dir_reg[PC]++; *dec=47680; dir_reg[instruction.op1_value]=REVG(dir_reg[instruction.op2_value]); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"REVSH") == 0 || strcmp(instruction.mnemonic,"REVSHS") == 0){ dir_reg[PC]++; *dec=47808; dir_reg[instruction.op1_value]=REVSH(dir_reg[instruction.op2_value]); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"ROR") == 0 || strcmp(instruction.mnemonic,"RORS") == 0){ dir_reg[PC]++; *dec=16832; if(instruction.op3_type=='#'){ dir_reg[instruction.op1_value]=ROR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);} else{ dir_reg[instruction.op1_value]=ROR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"RSB") == 0 || strcmp(instruction.mnemonic,"RSBS") == 0){ dir_reg[PC]++; *dec=16690; dir_reg[instruction.op1_value]=RSB(dir_reg[instruction.op2_value], dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"SBC") == 0 || strcmp(instruction.mnemonic,"SBCS") == 0){ dir_reg[PC]++; *dec=16768; SBC(dir_reg[instruction.op1_value],dir_reg[instruction.op2_value], dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"SUBS") == 0 || strcmp(instruction.mnemonic,"SUB") == 0){ dir_reg[PC]++; if(instruction.op2_type=='S'){ *dec=45184; dir_reg[SP]=SUB(dir_reg[SP],instruction.op3_value,dir_flags); *dec=*dec|instruction.op3_value;} else if(instruction.op3_type=='#'){ *dec=7680; dir_reg[instruction.op1_value]=SUB(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=6656; dir_reg[instruction.op1_value]=SUB(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if( strcmp(instruction.mnemonic,"TST") == 0 || strcmp(instruction.mnemonic,"TSTS") == 0){ dir_reg[PC]++; *dec=16896; TST(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_flags); *dec=*dec|instruction.op2_value<<3|instruction.op1_value; } if( strcmp(instruction.mnemonic,"NOP") == 0 ){ NOP(dir_reg); *dec=48896; } if( strcmp(instruction.mnemonic,"B") == 0 ){ *dec=57344; *dec=*dec|instruction.op1_value; B(instruction.op1_value, dir_reg); } if( strcmp(instruction.mnemonic,"BL") == 0 ){ *dec=0; BL(instruction.op1_value, dir_reg); } if( strcmp(instruction.mnemonic,"BX") == 0 ){ *dec=18176; BX(dir_reg); } if( strcmp(instruction.mnemonic,"BEQ") == 0 ){ *dec=0; BEQ(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BNE") == 0 ){ *dec=0; BNE(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BCS") == 0 ){ *dec=0; BCS(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BCC") == 0 ){ *dec=0; BCC(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BMI") == 0 ){ *dec=0; BMI(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BPL") == 0 ){ *dec=0; BPL(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BVS") == 0 ){ *dec=0; BVS(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BVC") == 0 ){ *dec=0; BVC(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BHI") == 0 ){ *dec=0; BHI(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BLS") == 0 ){ *dec=0; BLS(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BGE") == 0 ){ *dec=0; BGE(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BLT") == 0 ){ *dec=0; BLT(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BGT") == 0 ){ *dec=0; BGT(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BLE") == 0 ){ *dec=0; BLE(instruction.op1_value, dir_reg, dir_flags); } if( strcmp(instruction.mnemonic,"BAL") == 0 ){ *dec=0; BAL(instruction.op1_value, dir_reg); } if(strcmp(instruction.mnemonic,"PUSH")==0){ dir_reg[PC]++; *dec=46080; PUSH(SRAM, dir_reg,R_activos); } if(strcmp(instruction.mnemonic,"POP")==0){ dir_reg[PC]++; *dec=48128; POP(SRAM,dir_reg,R_activos); } data=(uint8_t)dir_reg[instruction.op1_value]; if(strcmp(instruction.mnemonic,"LDR")==0){ dir_reg[PC]++; if(instruction.op2_type=='=' && instruction.op3_type=='N'){ *dec=0; dir_reg[instruction.op1_value]=instruction.op2_value;} else if(instruction.op2_type=='S'){ *dec=38912; dir_reg[instruction.op1_value]=LDR(dir_reg[SP], instruction.op3_value<<2, SRAM); *dec=*dec|instruction.op3_value|instruction.op1_value<<8;} else if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=26624; if((dir_reg[instruction.op2_value]+(instruction.op3_value<<2))>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<2)), &data,Read); else dir_reg[instruction.op1_value]=LDR(dir_reg[instruction.op2_value], instruction.op3_value<<2, SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value|instruction.op1_value;} else{ *dec=22528; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read); else dir_reg[instruction.op1_value]=LDR(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if(strcmp(instruction.mnemonic,"LDRB")==0){ dir_reg[PC]++; if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=30720; if((dir_reg[instruction.op2_value]+instruction.op3_value)>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+instruction.op3_value), &data,Read); else dir_reg[instruction.op1_value]=LDRB(dir_reg[instruction.op2_value], instruction.op3_value, SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=23552; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read); else dir_reg[instruction.op1_value]=LDRB(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if(strcmp(instruction.mnemonic,"LDRH")==0){ dir_reg[PC]++; if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=34816; if((dir_reg[instruction.op2_value]+(instruction.op3_value<<1))>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<1)), &data,Read); else dir_reg[instruction.op1_value]=LDRH(dir_reg[instruction.op2_value], instruction.op3_value<<1, SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=23040; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read); else dir_reg[instruction.op1_value]=LDRH(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if(strcmp(instruction.mnemonic,"LDRSB")==0){ dir_reg[PC]++; *dec=22016; *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read); else dir_reg[instruction.op1_value]=LDRSB(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); } if(strcmp(instruction.mnemonic,"LDRSH")==0){ dir_reg[PC]++; *dec=24064; *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read); else dir_reg[instruction.op1_value]=LDRSH(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); } if(strcmp(instruction.mnemonic,"STR")==0){ dir_reg[PC]++; if(instruction.op2_type=='S'){ *dec=38912; STR(dir_reg[instruction.op1_value],dir_reg[SP], instruction.op3_value<<2, SRAM); *dec=*dec|instruction.op3_value|instruction.op1_value<<8;} else if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=24576; if((dir_reg[instruction.op2_value]+(instruction.op3_value<<2))>=0x40000000){ IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<2)), &data,Write);} else{ STR(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value<<2, SRAM);} *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value; mvprintw(1,3,"Hola");} else{ *dec=20480; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op2_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write); else{ STR(dir_reg[instruction.op1_value], instruction.op2_value, instruction.op3_value, SRAM);} *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if(strcmp(instruction.mnemonic,"STRB")==0){ dir_reg[PC]++; if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=28672; if(dir_reg[instruction.op2_value]+instruction.op3_value>=0x40000000){ IOAccess((uint8_t)(dir_reg[instruction.op2_value]+instruction.op3_value), &data,Write);} else{ STRB(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value, SRAM);} *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=21504; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000){ IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write);} else{ STRB(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);} *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } if(strcmp(instruction.mnemonic,"STRH")==0){ dir_reg[PC]++; if(instruction.op3_type=='#' || instruction.op3_type=='N'){ *dec=32768; if(((dir_reg[instruction.op2_value])+(instruction.op3_value<<1))>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<1)),&data,Write); else STRH(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value<<1, SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} else{ *dec=20992; if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000) IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write); else STRH(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM); *dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;} } }