int main() { /* */ char ascend_flag; unsigned int size, i; int arr[SIZE]; int **pointers; scanf("%u", &size); for (i = 0; i < size; i++) scanf("%d", &arr[i]); getchar(); scanf("%c", &ascend_flag); pointers = pointerSort(arr, size, ascend_flag); printPointers(pointers, size); return 0; }
// Execute Cycle void Execute() { fprintf(stacktrace_file, "%2d\t%s\t%d\t%d", IR.line, OPS[IR.OP], IR.L, IR.M); switch(IR.OP) { case LIT: sp++; stack[sp] = IR.M; break; case OPR: ALU(IR); break; case LOD: sp++; stack[sp] = stack[base(IR.L, bp) + IR.M]; break; case STO: stack[base(IR.L, bp) + IR.M] = stack[sp]; sp--; break; case CAL: current_level++; pipes[current_level] = sp + 1; stack[sp + 1] = 0; stack[sp + 2] = base(IR.L, bp); stack[sp + 3] = bp; stack[sp + 4] = pc; bp = sp + 1; pc = IR.M; break; case INC: sp = sp + IR.M; break; case JMP: pc = IR.M; break; case JPC: if( stack[sp] == 0 ) { pc = IR.M; } sp--; break; case SIO1: fprintf(stacktrace_file, "%d\n", stack[sp]); sp--; break; case SIO2: sp++; scanf("%d", &stack[sp]); break; case SIO3: pc = 0; bp = 0; sp = 0; break; default: printf("Invalid Operation\n"); fprintf(stacktrace_file, "Invalid Operation\n"); HALT = true; } if(!HALT) { printPointers(); printStack(); } }
void RegressionTask(void) { int retValue; /* task_mem_map_xxx interface return value */ void *b; /* Pointer to memory block */ void *ptr[NUMBLOCKS]; /* Pointer to memory block */ /* Part 1 of test */ TC_START("Test Microkernel Memory Maps"); TC_PRINT("Starts %s\n", __func__); /* Test task_mem_map_alloc */ tcRC = testMapGetAllBlocks(ptr); if (tcRC == TC_FAIL) { TC_ERROR("Failed testMapGetAllBlocks function\n"); goto exitTest; /* terminate test */ } printPointers(ptr); /* Test task_mem_map_free */ tcRC = testMapFreeAllBlocks(ptr); if (tcRC == TC_FAIL) { TC_ERROR("Failed testMapFreeAllBlocks function\n"); goto exitTest; /* terminate test */ } printPointers(ptr); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run */ /* Wait for HelperTask to finish */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); /* * Part 3 of test. * * HelperTask got all memory blocks. There is no free block left. * The call will timeout. Note that control does not switch back to * HelperTask as it is waiting for SEM_REGRESSDONE. */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, 2); if (verifyRetValue(RC_TIME, retValue)) { TC_PRINT("%s: task_mem_map_alloc timeout expected\n", __func__); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } TC_PRINT("%s: start to wait for block\n", __func__); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run part 4 */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, 5); if (verifyRetValue(RC_OK, retValue)) { TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n", __func__, b); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } /* Wait for HelperTask to complete */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); TC_PRINT("%s: start to wait for block\n", __func__); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run part 5 */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, TICKS_UNLIMITED); if (verifyRetValue(RC_OK, retValue)) { TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n", __func__, b); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } /* Wait for HelperTask to complete */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); /* Free memory block */ TC_PRINT("%s: Used %d block\n", __func__, task_mem_map_used_get(MAP_LgBlks)); task_mem_map_free(MAP_LgBlks, &b); TC_PRINT("%s: 1 block freed, used %d block\n", __func__, task_mem_map_used_get(MAP_LgBlks)); exitTest: TC_END_RESULT(tcRC); TC_END_REPORT(tcRC); } /* RegressionTask */