UMBC Project 2 CMSC313

Project 2 Due: 27 Oct

Requirements Specification

Create the source file jdoe2p2asm.asm and jdoe2p2c.c, assembly it, link it, and run it. When it runs correctly, submit using Blackboard. (Remember that the jdoe2 is suppose to be your login ID at UMBC! This program will be written in two languages, C/C++ (your choice) and assembly language. If you use C++, you may not use the Standard Template Library for this!

Data Structures

This program will create a doubly-linked list of nodes which will contain the address of the next node, the address of the previous node, and the address of the data node. The first node will not have a previous node, so it will be set to NULL. Likewise the last node will not have a next node, so it too will be set to NULL. Each new node will be added to the linked list at the end (tail) of the list.

The data node will contain information about students. It will have their name, address, and year first enrolled at UMBC (it must hold all four digits).

Each link node in the list will contain a pointer to the next and previous nodes, a name of up to 27 characters (counting the null terminator because C/C++ must have the null terminator to print it out), an address of up to 53 characters, and an integer number for the year of first enrollment at UMBC. The list must be printed out in columnar format as shown in the example below.

Your program will begin in the C function of main. You will have to declare two structures for your two types of nodes. The C code should then prompt the user for the number of nodes you wish for this execution of the program.

Then the C program will make a call to your assembly language subprogram, which will allocate memory for each node (both types), populate the nodes with the necessary data, and maintain the linked list.

After all the nodes have been properly created, return to the C program, which will print out the list in reverse order as well as the name of the student who has been at UMBC the longest (show the starting year).

Note: There is only one call to the assembly language subprogram in the C program! 19 Oct

You can use any system call or C/C++ library function that you wish to use. You will have to use the malloc (or calloc) call to create a new node. See the man page for details. You must ensure that the year is between 1980 and 2010 (in case we keep using this program).

Hints for Linked Lists

Since a number of you have not had our Data Structures course yet, you will have to get a book that shows how linked lists are developed in used. (The library should have many books with this.) But normally, you will start with a variable (often called head) that holds a pointer to the first node, if present. Otherwise your code should assign a null value to the pointer.

First Node

All nodes are created by asking the operating system to dynamically allocate a block of memory to the process for this purpose. The address for this node is then stored in head. In our case, you will need to set the next and previous pointers to null. Then you will have to allocate more memory for the data node. You will store the address for this new new in the previous node's dataNode pointer. Now you can fill in the data in the dataNode.

All Other Nodes

All other nodes must be added to the end of the of the list:
  1. You can go to the node pointed to by head
  2. Check the current node's next pointer.
  3. if the current's nodes next pointer is null, add the new node here. Otherwise, go to the node pointed to by next. and return to step 2.

To add a new node, you must put the address of the new node into the pointer next of what was previously the tail, make the new node's previous pointer point to the old tail and make the new next set to null.

Print Out The List In Reverse Order

In order to print out the list in reverse order, you must traverse the list until you find the tail. You do this by going to each node and checking it's next pointer. When you find a null, then you have found the tail. Print out the information and go to the node pointed to by the previous pointer. Print that node and go to next previous if the pointer is not a null. If it is a null, then you are finished.

Sample of a C Program Calling An Assembly Language Subprogram

Since you have no references that show how to do this, I am including a sample set of the two files. It is actually easier that it sounds.
#include 

extern void p2asm( void );     /* Prototype for for assembly language subprogram */

int main( void )
{

  printf("Going\n");
  p2asm( );                    /* Actual call to the assembly language subprogram */
  printf("Back\n");

  return 0;
  
}
  

Sample Of An Assembly Language Subprogram

There is nothing special about the subpgrogam. I will point out three items:


section .data
msg		db	'In assembly', 10,0

section .bss

section .text

global  p2asm

extern	printf


p2asm:


	push	dword msg
	call	printf
	add	esp, 4

	ret

Compiling

Assuming that you call your assembly subprogram jdoe2p2asm, you will have to make the label jdoe2p2asm global in the .asm file: global jdoe2p2asm You can not have a main in the assembly file. In the C file, you will have to have a prototype and assuming that your address nodes structure is called linkedList, it would look like: extern struct linkedList *jdoe2p2asm( int max );

I recommend that you use the make system and your Makefile will look like something like this:

p2 : p2c.c  
	nasm -g -f elf p2asm.asm 
	gcc -g -o p2 p2c.c p2asm.o
clean : 
	rm p2 p2.o p2c.c~ p2asm.o p2asm.asm~
  

Sample Output

Your program must output the results in the following manner, where the program output is in blue, user input is in red:
[~/courses/umbc/CMSC313/spring04/proj3]$ proj3
Enter the maximum number of nodes to be created? 4
Enter the name: Gretchen
Enter the address: 123 Main Street, Hometown, USA
Enter the year student enrolled at UMBC: 1997
Enter the name: Sammi
Enter the address: 456 Main Street, Hometown, USA
Enter the year student enrolled at UMBC: 2004
Enter the name: Jessica
Enter the address: 456 Main Street, Hometown, USA
Enter the year student enrolled at UMBC: 2003
Enter the name: Danny
Enter the address: 123 Main Street, Hometown, USA
Enter the year student enrolled at UMBC: 1980

Danny has been at UMBC the longest, since 1980.

Gretchen                         123 Main Street, Hometown, USA  1997
Sammi                            456 Main Street, Hometown, USA  2004
Jessica                          456 Main Street, Hometown, USA  2003
Danny                            123 Main Street, Hometown, USA  1980


Program Header Comment Block

Use the following comment block at the beginning of your source code:
;; Filename:       jdoe2p2asm.asm
;; Name:           Ima Student
;; email:          jdoe2@umbc.edu  
;; Date:           7 Oct 2004
;; Course:         CMSC313 
;; Description:    (Your psuedocode goes here.  Must be detailed)
;; Notes:          (As needed, such has how to compile)
Obviously, your C program will be in a file jdoe2p2c.c and have a similiar program header comment block.