MIPS Assembly Pointer help

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 1
Reputation: belikemike121 is an unknown quantity at this point 
Solved Threads: 0
belikemike121 belikemike121 is offline Offline
Newbie Poster

MIPS Assembly Pointer help

 
0
  #1
Sep 17th, 2008
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!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC