Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppc register printing outputs noise #4

Open
slugrustle opened this issue Aug 9, 2021 · 0 comments
Open

ppc register printing outputs noise #4

slugrustle opened this issue Aug 9, 2021 · 0 comments

Comments

@slugrustle
Copy link

slugrustle commented Aug 9, 2021

I find that running ppc outputs noise after the register values.

Enter a command: ppc
Current Address: 16
Offset: 0
Address Word: 000000000000000000000000000000000000spotIè9♦[ò
Instruction: 000000000000000000ram FiKè9♠Zò
Multiplier Quoticent: 000000000000000000000000000000000000spotⁿè8░[ò
Accumulator: 00000000000000000000000000000000000000R=Lè9☺[ò
Accumulator Int: 0
Multiplier Qotient: 0
Combined Int: 0

Adding length limitations to the string format codes fixed this issue on my system. It appears the strings are not null terminated.

void print_pc(struct program_counter pc)
{

    printf("Current Address: %d\n", pc.current_address);
    printf("Offset: %d\n", pc.offset);

    char* address_word = malloc(WORD_SIZE);
    byte_value_to_string(pc.address_word, address_word, WORD_SIZE);
    printf("Address Word: %.*s\n", WORD_SIZE, address_word);

    char* instruction_string = malloc(INSTRUCTION_SIZE);
    byte_value_to_string(pc.instruction, instruction_string, INSTRUCTION_SIZE);
    printf("Instruction: %.*s\n", INSTRUCTION_SIZE, instruction_string);

    byte_value_to_string(pc.multiplier_quotient, address_word, WORD_SIZE);
    printf("Multiplier Quoticent: %.*s\n", WORD_SIZE, address_word);

    char* accumulator_string = (char*) malloc(ACCUMULATOR_SIZE);
    byte_value_to_string(pc.accumulator, accumulator_string, ACCUMULATOR_SIZE);
    printf("Accumulator: %.*s\n", ACCUMULATOR_SIZE, accumulator_string);    

    printf("Accumulator Int: %lld\n",signed_byte_value(pc.accumulator,ACCUMULATOR_SIZE));
    printf("Multiplier Qotient: %lld\n",signed_byte_value(pc.multiplier_quotient, MULTIPLIER_QUOTIENT_SIZE));

    printf("Combined Int: %lld\n\n",compute_multiplier_accumulator(&pc));

    free(address_word);
    free(instruction_string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant