Arm/linklist len

From ASMBits

In this problem, we will be working with a simple linked list. Each list element only contains a single word that is a pointer to the next node in the list. A pointer with value 0 (null pointer) indicates that the current node is the end of the list.

Write a function that will find the length of the linked list beginning at the node passed to the function as the first argument. A null pointer should return length 0. Do not attempt to detect cycles in the linked list (Cycles should cause your function to run forever.)

struct node { node *next; };
unsigned int listlen(node* list);

Expected solution length: Around 10 lines.

Sample Input

A -> B -> C -> null

Sample Output

3

Write your solution here

x
 
1
.data
2
A: .word B
3
B: .word C
4
C: .word 0
5
.text
6
.global _start
7
    ldr r0, =A
8
    bl listlen
9
1:  b 1b  // done
10
11
.global listlen
12
listlen:
13
    
14
    
Upload a source file...