Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- enum
- {
- DECIMAL_BASE = 10,
- INIT_VALUE = -1,
- WRITE = 'W',
- READ = 'R'
- };
- int
- main (int argc, char *argv[])
- {
- int cache_size = strtol(argv[2], NULL, DECIMAL_BASE);
- int block_size = strtol(argv[3], NULL, DECIMAL_BASE);
- int miss = 0;
- int block_amount = cache_size / block_size;
- int *block_array = malloc(block_amount * sizeof(block_amount));
- if (block_array == NULL) {
- return 1;
- }
- for (int i = 0; i < block_amount; ++i) {
- block_array[i] = INIT_VALUE;
- }
- char rdwr, datainstruction;
- int addr, size, value;
- while (scanf("%c%c%x%d%d\n", &rdwr,
- &datainstruction, &addr, &size, &value) == 1) {
- int block_index = addr / block_size;
- if (rdwr == READ) {
- if ((block_index != block_array[block_index % block_amount])
- && (block_array[block_index % block_amount] != -1)) {
- miss++;
- }
- block_array[block_index % block_amount] = block_index;
- } else if (rdwr == WRITE) {
- block_array[block_index % block_amount] = block_index;
- }
- }
- printf("%d\n", miss);
- fflush(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement