various bugfixes, refractoring

This commit is contained in:
nova 2024-05-01 21:32:06 +02:00
parent 763c447cf5
commit 46aa1e9ce9

18
main.c
View File

@ -36,13 +36,13 @@ int main(int argc, char **argv) {
asm_rules(in_asm, out_asm); asm_rules(in_asm, out_asm);
asm_to_hex(out_asm, &hex_op, &hex_in0, &hex_in1, &hex_out); asm_to_hex(out_asm, &hex_op, &hex_in0, &hex_in1, &hex_out);
printf("%.5x %.5x %.5x %.5x\n", hex_op, hex_in0, hex_in1, hex_out); printf("%.7x %.7x %.7x %.7x\n", hex_op, hex_in0, hex_in1, hex_out);
// Write the hex to a file // Write the hex to a file
fprintf(dest_asm,"%.5x ", hex_op); fprintf(dest_asm,"%.7x ", hex_op);
fprintf(dest_asm,"%.5x ", hex_in0); fprintf(dest_asm,"%.7x ", hex_in0);
fprintf(dest_asm,"%.5x ", hex_in1); fprintf(dest_asm,"%.7x ", hex_in1);
fprintf(dest_asm,"%.5x \n", hex_out); fprintf(dest_asm,"%.7x \n", hex_out);
size = size + 3; //1 word = 3trytes size = size + 2; //1 word = 2trytes
} }
} }
@ -102,9 +102,9 @@ void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){
//convert assembly to formated binary representation of ternary //convert assembly to formated binary representation of ternary
int i = 0; int i = 0;
do { do {
if(_asm[0]=='-') { if(_asm[i]=='-') {
strcat(tryte, "10"); strcat(tryte, "10");
} else if (_asm[0]=='+') { } else if (_asm[i]=='+') {
strcat(tryte, "01"); strcat(tryte, "01");
} else { } else {
strcat(tryte, "00"); strcat(tryte, "00");
@ -117,7 +117,7 @@ void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){
t0[i] = tryte[j]; t0[i] = tryte[j];
j++; j++;
} }
j++; printf("%s\n",t0);
bin_to_hex(t0, opcode); bin_to_hex(t0, opcode);
bin_to_hex(t1, in0); bin_to_hex(t1, in0);