Question

Write a short program of five to ten lines in MARIE assembly language to accomplish something Note: In our version of Null and Lobur, labels are assigned differently than in later versions and by the community as a whole. That is the label Addr on line 112 (in Listing 4.1) is written as Addr, 112 Hex In later versions and in most textbooks, it would be written 112 Addr, Hex with the label written after the line number Also there is an error in Null and Lobur in Chapter 4.1.5. There are two occurrences where 2 12 should be 2 22

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

#include
#include

typedef struct nod
{
   int data;
   struct nod * next;
}node;


void insert( node ** head , int data , node ** tail)
{
   node * temp = (node*)malloc( sizeof(node) );
   temp->data = data;
   temp->next = NULL;

   if ( !(*head))
   {
      *head = temp;
      return ;
   }
   node * pre = NULL;
   node * cur = * head;
   node * nxt = NULL;
   
   while( cur->next != pre)
   {
      nxt = (node*)((unsigned int)cur->next ^(unsigned int)pre);
      pre = cur;
      cur = nxt;
   }

   cur->next = (node*)((unsigned int)cur->next^(unsigned int)temp);
   temp->next = cur ;
   *tail = temp ;
   return;
}

void print( node * head )
{
   node * pre = NULL;
   node * cur = head;
   node * nxt = NULL;
   while( cur )
   {
      printf(" %d ",cur->data);
      nxt = (node*)((unsigned int)cur->next ^(unsigned int)pre);
      pre = cur;
      cur = nxt;
   }
   printf("NULL\n");
   return;
}

int main()
{
   node * head = NULL;
   node * tail = NULL;
   insert(&head,3,&tail);
   insert(&head,5,&tail);
   insert(&head,7,&tail);
   insert(&head,11,&tail);
   insert(&head,13,&tail);
   print( head );
   print( tail );
   return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a short program of five to ten lines in MARIE assembly language to accomplish something...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT