UMBC | Project 3 | CMSC313 |
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.
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.
#includeextern 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; }
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
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
[~/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
;; 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)