954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MIPS Assembly Pointer help

Hi all, I've spent hours on this and could not get it to work. There also does not appear to be too much help on the subject online so I'm hoping you can help me!

I am implementing a Binary Search Tree in MIPS assembly. I'm having trouble with my insert routine.

My struct for the node is:
typedef struct node_s {
int data;
struct node_s *left;
struct node_s *right;
} node_t;

The C function I'm having problems with is:

void insert_value(node_t** root, int x) {
if (root == NULL) {
*root = generate_new_node(x);
}
else {
if ((*root)->data == x) return;
if ((*root)->data > x) insert_value(&(*root)->left, x);
else insert_value(&(*root)->right, x);
}
}
}

In my MIPS program, generate_new_node is working fine and my conditionals are working correctly as well. The line that is giving me troubles is:

&(*root)->left

My insert_value takes in a double pointer, therefore when calling it recursively I need to get the address to the pointer of the node_t stored in left.

I can get (*root)->left doing:
move $s0, 0($a0) # $s0 = *root
lw $a0, 4($a0) # $a0 = (*root)->left

However how can I get &((*root)->left)?

I need this urgently. Any help would be much appreciated!!

belikemike121
Newbie Poster
1 post since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You