通过引用传递struct更新它,然后在main中获取不同的成员值

时间:2015-06-01 16:48:37

标签: c

标题说这一切都是有问题的代码:

基本上会发生的是,管道结构成员args的值在程序的各个阶段都不会发生变化,这显然是一个问题,因为它会导致程序中其他位依赖于其值的段错误。 / p>

这主要是:

insert value2

这是代码decode_data_proc,它是在decode中传递参数的地方。

int cycle = 1;
  do {
    printf("Block here %i \n", cycle);
    if (cycle == 3) {
      printf("%u, args[2]\n", pip_ptr->decoded_args[2]);
    }
    pip_ptr->decoded (pip_ptr->decoded_args, mach_ptr);
    decode(cycle, pip_ptr->fetched, pip_ptr, mach_ptr); 
    if(cycle == 2) {
      printf("%u, before fetch args[2]\n", pip_ptr->decoded_args[2]);
    }
    fetch(pc, pip_ptr, mach_ptr);
    printf("%u fetched\n", *(pip_ptr->fetched));
    if(cycle == 2) {
      printf("%u, after fetched args[2]\n", pip_ptr->decoded_args[2]);
    }
    pc += 4;
    cycle ++;
    output_machine_state(mach_ptr);
  } while (pip_ptr->halt == 0);

现在所有decode_data_proc引用的代码

`void decode_data_proc(uint32_t instr, struct pipeline *pip, struct machine_state
                    *mach) {
void (*op_ptrs[14]) (uint32_t* args, struct machine_state *mach);

op_ptrs[0] = ∧
op_ptrs[1] = &eor;
op_ptrs[2] = ⊂
op_ptrs[3] = &rsb;
op_ptrs[4] = &add;
op_ptrs[8] = &tst;
op_ptrs[9] = &teq;
op_ptrs[10] = &cmp;
op_ptrs[12] = &orr;
op_ptrs[13] = &mov;

pip->decoded_args = process_args(instr, mach);
pip->decoded = op_ptrs[extract_bits(instr, 21, 4)];
printf("%u passed dest reg\n", pip->decoded_args[2]);
}`

如果你们想知道我试图模仿ARM11架构,那么args就是存储要执行的指令的参数的地方。

0 个答案:

没有答案