RISC-V assembly
Which registers contain arguments to functions? For example, which register holds 13 in main's call to printf?
根据RISC-V函数调用规范,函数的前8个参数使用a0-a7寄存器传递。
当main函数调用printf函数时,a2寄存器保存13
Where is the call to function f in the assembly code for main? Where is the call to g? (Hint: the compiler may inline functions.)
通过 li a1,12 可知,当main函数调用函数 f 时,已经内联了函数 f ,所以可以看到编译器直接将12保存到寄存器a1中
而在函数 f 中,编译器也内联了函数 g 的调用,直接向a0 寄存器加3
At what address is the function printf located?
0x0000000000000642
What value is in the register ra just after the jalr to printf in main?
0x38
Run the following code. What is the output? The output depends on that fact that the RISC-V is little-endian. If the RISC-V were instead big-endian what would you set i
to in order to yield the same output? Would you need to change 57616
to a different value?
unsigned int i = 0x00646c72;
printf("H%x Wo%s", 57616, &i);
输出: He110 World
如果是大端机器,57616 不用变,i 变为 0x726c6400
In the following code, what is going to be printed after 'y='
? (note: the answer is not a specific value.) Why does this happen?
printf("x=%d y=%d", 3);
a2寄存器中的值
Backtrace
void backtrace(void)
{uint64 ra;uint64 fp = r_fp();uint64 up = PGROUNDUP(fp);printf("backtrace:\n");while (fp < up){ra = fp - 8;printf("%p\n",*(uint64*)ra);fp = *(uint64*)(fp - 16);}
}