What value is in the register ra just after the jalr to printf in main?
0x38
执行jalr前的PC是0x34,执行后PC+4得到0x38
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 i=0x726c6400 No
hello部分很好解释,57616=0xE110
注意到RISC-V是小端序的,因此i值每两位转化为一个char的话就会变为rld'\0'
若改成大端序,就需要把i的值改成大端;57616的打印与大小端无关,因此不用改变
In the following code, what is going to be printed after 'y='? (note: the answer is not a specific value.) Why does this happen?
x=3 y=1130405448
We put one argument to the register(actually we need two), but printf still reads value from a2 register, so the function takes a random value from that register as its argument.
// trap.c//// handle an interrupt, exception, or system call from user space.// called from trampoline.S//// void usertrap(void)// give up the CPU if this is a timer interrupt.if(which_dev ==2){if(!p->alarm_on && p->alarm_ticks &&++p->alarm_past == p->alarm_ticks){
p->alarm_on =1;*p->pre_trapframe =*p->trapframe;
p->alarm_past =0;
p->trapframe->epc =(uint64)p->alarm_handler;}yield();}