I need to write the following C code in NIOS II assembly code. and know the stack state from the L1 label.
struct lelt
{
int value;
struct lelt* next;
}
struct lelt x = {3,NULL};
lelt* get_tail(lelt *ptr)
{
lelt* last;
L1: last = NULL;
while(ptr != NULL)
{
last = ptr;
ptr = ptr -> next;
}
return last;
}
Here's what I've wrote till now but I don't know how to manage the write the rest of the code because I'm not very familiar with the structs in assembly code. So if someone can help me out and explain a little bit I'd be grateful.
x:
value .word 3
next .word 0
get_tail:
subi sp, sp,12
stw ra, 0(sp)
stw r16, 4(sp) // ptr
stw r17, 8(sp) // last
movia r16,zero,r4
bne r4,zero,endwhile
add r17,zero,r16
... // i don't know how to write ptr=ptr->next
endwhile:
add r2,r17,zero
br end
end:
ldw ra,0(sp)
ldw r16,4(sp)
ldw r17,8(sp)
addi sp,sp,12
ret