UMBC Project 3 CMSC313

Project 3 Due: 1 April

Requirements Specfication

Create the source file 6789prj3asm.asm and 6789prj3c.c, assembly it, link it, and run it. When it runs correctly, submit using Blackboard. (Remember that the 6789 is suppose to be the last four digits of your SSN, so that there is a unique file! Do not use 6789 unless that is in YOUR SSN!!)

This program will be written in two languages, C (your choice) and assembly language. This program will create a doubly-linked list from user-provided input data. This data will be information about students. It will have their name, age, and number of semester hour credits (but since they can transfer in quarter hours that must be converted semester hours, the number can contain a fraction). The number of nodes will be provided by user input (from the C code), the number of nodes will be passed as a parameter to the assembly language code, which will get the data from the user and return the address of the head of list to the C code. The C program will print out the linked list in the forward order.

Each 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), a floating point number (of type float) for the nubmer of credits, and an integer for the student's age. The list must be printed out in columnar format as shown in the example below. The C compiler can add bytes to force items to begin on a word or double word boundary (The hardware likes those addresses better!)

You can use any system call or C library function that you wish to use. You must ensure that the number of credits is non-negative and the age is positive.

Building The Executable

nasm -g -f elf -l 6789prj3asm.lst 6789prj3asm.asm
gcc -o 6789prj3 6789prj3c.c 6789prj3asm.o

You must turn in both the .c and .asm files.

Mixed Language Programming

When mixing C and assembly language code that are in different files, it is very simple. There are a couple of things to remember: To help you out without giving you the answers, I have a sample program and have the two files, one .c and one .asm. This does not address the issue of the structure in C, though. Remember that those definitions are restricted to one file, and the definitions are not passed to the linker, so you have to do one version in C and one in assembly, in the proper syntax for each. In assembly, you can treat the structure as an array or can attempt to use a struct as explained in the NASM manual, Section 4.8.5.

Example

C
#include 

extern int foo( int i );   /* this is for the foo.asm subprogram */

int main( void )
{
    int age;               /* age in months */           
    age = foo( 3 );        /* convert three years to months */

    printf( "age in months is %d\n", age );
    return 0;

  
}


Assembly Language

section .data
months	dd	0

section .bss

section .text

global  foo



foo:

	push	ebx
	mov	ebx, esp
	push	ecx
	push	edx

	mov	ecx, [ ebx + 8 ]  ; get years
	mov	eax, 12
	mov	edx, 0
	mul	ecx
	mov	[ months ], eax

	pop	edx
	pop	ecx
	pop	ebx
	mov	eax, [ months ]
	ret

Short program to check to see if a floating point number is greater than or equal to zero

section .data

fnr1	dd	-2.0			; Value to check
good	db	'Good', 10, 0
bad	db	'Bad', 10, 0

section .bss

section .text
    global main                       ;must be declared for linker (ld)
;; just like main in C -- if linking with gcc, must be main, otherwise does not have to.

main:                                 ;tell linker entry point

extern	printf

;; put your code here

	fld	dword [ fnr1 ]		; Load value into the FPU where it can be compared.
	ftst				; Negative numbers not allowed, test it against zero.
	fstsw	ax			; move the FPU flags into AX register
	sahf				; put the FPU flags into the CPU flags
	jae	OK                      ; It if it not negative (below), we are good
	push	bad                     ; bad dog!
	call	printf			; Notify the user
	add	esp,4                   ; Usual housekeeping

	jmp	quit

OK:
	push	good                    ; Good boy, Ubu
	call	printf			; Notify the user
	add	esp, 4			; Usual housekeeping

quit:
        mov     ebx,0   		;successful termination of program
        mov     eax,1   		;system call number (sys_exit)
        int     0x80    		;call kernel


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
How many nodes will there be? 4
Enter the name: Gretchen
Enter the number of credits: 15.5
Enter age: 14
Enter the name: Sammi
Enter the number of credits: 20
Enter age: 15
Enter the name: Jessica
Enter the number of credits: 55
Enter age: 19
Enter the name: Danny
Enter the number of credits: 50
Enter age: 20

Name                          Credits Age
Danny                            50.0  20
Jessica                          55.0  19
Sammi                            20.0  15
Gretchen                         15.5  14


Program Header Comment Block

Use the following comment block at the beginning of your source code:
;; Filename:       6789prj3.asm
;; Name:           Ima Student
;; SSAN:           6789  
;; Date:           7 Mar 2004
;; Course:         CMSC313 
;; Description:    (Your psuedocode goes here.  Must be detailed)
;; Notes:          (As needed, such has how to compile)