How would we write assembly code for a linked list We want t

How would we write assembly code for a linked list? We want to extract the positive and negative numbers, but the part I\'m struggling with is how to make the linked list , especially since the sections (A,B,C, etc.) are so different. We use the NIOSII interface for assembly language.

IN LINKED LIST A word 1 word B B: word -1 word C C: word -2 word E 8 D: word 2 word C E word 0 word K F word word G G word 100 word J H word Oxffffff9c word E I word Oxff9c word H J: word 0b1 111 word IN LINKED LIST 0x40 K byte 0x01 byte 0x02 byte 0x03 byte 0x04 word 0 Used only in Part 3 address K address K+1 address K-12 address K+3

Solution

#include<stdio.h>
#include<conio.h>
#include<alloc.h>

/* structure containing a data part and link part */
struct node
{
int data ;
struct node *link ;
} ;

void add ( struct node **, int ) ;
void display ( struct node * ) ;


void main( )
{
struct node *first, *second, *third ;
int n,i,num;
clrscr();
first = second = NULL ; /* empty linked lists */
printf(“\ Enter total number elements of list : \ ”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“\ enter %d element(positive or negative number) : “,i+1);
scanf(“%d”,&num);
if(num<0)
add ( &first, num) ;
else
add ( &second, num) ;
}
printf ( “\ —–first linked list is —–\ : “) ;
display ( first ) ;

printf ( “\ \ Second linked list : “) ;
display ( second ) ;

getch();
}

/* adds node to an ascending order linked list */
void add ( struct node **q, int num )
{
struct node *r, *temp = *q ;

r = malloc ( sizeof ( struct node ) ) ;
r-> data = num ;

/* if list is empty or if new node is to be inserted before the first node */
if ( *q == NULL || ( *q ) -> data > num )
{
*q = r ;
( *q ) -> link = temp ;
}
else
{
/* traverse the entire linked list to search the position to insert the new node */
while ( temp != NULL )
{
if ( temp -> data < num && ( temp -> link -> data > num ||
temp -> link == NULL ))
{
r -> link = temp -> link ;
temp -> link = r ;
return ;
}
temp = temp -> link ; /*go to next node */
}

r -> link = NULL ;
temp -> link = r ;
}
}

/* displays the contents of the linked list */
void display ( struct node *q )
{
printf ( “\ ” ) ;

/* traverse the entire linked list */
while ( q != NULL )
{
printf ( “%d “, q -> data ) ;
q = q -> link ;
}
}

How would we write assembly code for a linked list? We want to extract the positive and negative numbers, but the part I\'m struggling with is how to make the l
How would we write assembly code for a linked list? We want to extract the positive and negative numbers, but the part I\'m struggling with is how to make the l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site