A null (zero) is placed in the link field of the last node. (Actually, for SPIM, a zero is already there. But with a real OS where dynamic memory is both allocated and deallocated you must be sure to zero the link.)
Now the linked list has been constructed.
The field first
points to the first node.
Here is some code from the previous chapter.
The code traverses a linked list, printing out
the data found at each node.
_____ ___,_______ # get a pointer to the first element
lp: beqz $s0,endlp # while the pointer is not null
lw $a0,0($s0) # get the data of this element
# do something with the element
li $v0,1 # print it
syscall #
la $a0,sep # print separator
li $v0,4 #
syscall #
lw $s0,4($s0) # get the pointer to the next element
b lp
endlp: . . .
.data
first: .word 0
sep: .asciiz " "
Our new linked list has the same form as the previous chapter's linked list. This code will work fine.