NJU NEMU

PA1:

1.返回q值出现的错误:2021 NEMU PA1 RTFSC 优美地退出_LoveAsukaFoever的博客-CSDN博客

nemu/src/utils state.c 中的最后!good该为good即可

2.在cmd_c()函数中, 调用cpu_exec()的时候传入了参数-1, 你知道这是什么意思吗?:

答:在cpu_exec.c文件中找到了函数 cpu_exec()。
在这里插入图片描述

n是无符号整型,所以-1就是无符号最大的数字,那么函数里的for循环可以执行最大次数的循环,从而让cpu处理之后的指令

3.单步执行:nemu/src/monitor/sdb/sdb.c中加上:

//增加
static int cmd_si(char *args) {
	int step;
	if (args == NULL) step = 1;
	else sscanf(args, "%d", &step);
	cpu_exec(step);
	return 0;
}

//修改
static struct {
  const char *name;
  const char *description;
  int (*handler) (char *);
} cmd_table [] = {
  { "help", "Display informations about all supported commands", cmd_help },
  { "c", "Continue the execution of the program", cmd_c },
  { "q", "Exit NEMU", cmd_q },
  {"si","单步执行", cmd_si},

  /* TODO: Add more commands */

};


版权声明:本文为qq_44836676原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。