CMSC313, Computer Organization & Assembly Language Programming, Spring 2013

Project 4: Indexed Addressing

Due: Tuesday March 12, 2013, 11:59pm


Objective

The objective of this programming project is to gain experience writing assembly language code using indexed addressing modes.


Background

Your assembly language program for this project will work with a linked list that is defined in a C program. Each node of the linked list contains data about an e-book. The data type for a node is declared as: typedef struct book { char title[48] ; char author[48] ; // first author char subject[20] ; // Nonfiction, Fantasy, Mystery, ... unsigned int year ; // year of e-book release struct book *next ; } book ;

In memory, each struct book occupies a contiguous block of memory. Each field of the struct is placed right after the previous one. This can be observed in the gdb debugger. (In this example, B031 is a struct book):

(gdb) print B031 $1 = {title = "Breaking Point", '\000' <repeats 33 times>, author = "Pamela Clare", '\000' <repeats 35 times>, subject = "Romance", '\000' <repeats 12 times>, year = 2011, next = 0x804a2e0} (gdb) print &B031 $2 = (book *) 0x804a3a0 (gdb) print &B031.title $3 = (char (*)[48]) 0x804a3a0 (gdb) print &B031.author $4 = (char (*)[48]) 0x804a3d0 (gdb) print &B031.subject $5 = (char (*)[20]) 0x804a400 (gdb) print &B031.year $6 = (unsigned int *) 0x804a414 (gdb) print &B031.next $7 = (struct book **) 0x804a418

Using this information we can define offsets for each field of the struct:

; Offsets for fields in struct book. ; %define TITLE_OFFSET 0 %define AUTHOR_OFFSET 48 %define SUBJECT_OFFSET 96 %define YEAR_OFFSET 116 %define NEXT_OFFSET 120

For example, if the ESI register holds the address of B031, then [ESI+YEAR_OFFSET] can be used to reference the year field of the struct. Similarly, [ESI+ECX+SUBJECT_OFFSET] can be used to access the i-th character of the subject string where the value of i is stored in ECX.

The last field of struct book is a pointer --- i.e., an address -- of another struct book. This field allows us to connect the nodes into a linked list. In the debugger session above, we can print out the address of another struct book and notice that it is the one referenced in the next field of B031.

(gdb) print B031.next $1 = (struct book *) 0x804a300 (gdb) print &B030 $8 = (book *) 0x804a2e0


Assignment

Your assignment is to write an assembly language program that traverses a linked list of struct book's and prints out all the e-books that have Fantasy as the subject. You must make good use of indexed addressing modes. You will be graded on how well you use indexed addressing modes.

Note: some CPU's do not support indexed addressing modes, so it is always possible to write an assembly language program that avoids using indexed addressing modes. However, if you submit a program that does not make good use of indexed addressing modes for this project, you will lose a significant number of points in your grade.

A data file is provided for you. This data file must be copied on the GL filesystem to your account. The file resides in:

/afs/umbc.edu/users/c/h/chang/pub/cs313/data4.o

When you assemble your program, you must include data4.o when you issue the ld command. That is, your compilation command should look like:

linux2% nasm -f elf -g fantasy.asm linux2% ld fantasy.o data4.o

The records in the data4.o file contain the information for these e-books:

Breaking Point, Pamela Clare, Romance, 2011 Vow, Kim Carpenter, Nonfiction, 2012 1491, Charles C. Mann, Nonfiction, 2006 Three Weeks with My Brother, Nicholas Sparks, Nonfiction, 2004 The 10 Habits of Happy Mothers, Meg Meeker, M.D., Nonfiction, 2011 We Need to Talk About Kevin, Lionel Shriver, Fiction, 2011 The Prague Cemetery, Umberto Eco, Fiction, 2011 Black Dahlia & White Rose, Joyce Carol Oates, Fiction, 2012 Glad Tidings, Debbie Macomber, Romance, 2012 A Summer Affair, Elin Hilderbrand, Romance, 2008 Dead until Dark, Charlaine Harris, Fantasy, 2001 Between the Dark and the Daylight, Richard Marsh, Mystery, 2012 Good Girls Don't, Victoria Dahl, Romance, 2011 Inheritance, Christopher Paolini, Fantasy, 2011 Best Staged Plans, Claire Cook, Fiction, 2011 The Gap Year, Sarah Bird, Humor, 2011 The Affair Next Door, Anna Katherine Green, Mystery, 2012 Crossed, Ally Condie, Romance, 2011 Eclipse, Stephenie Meyer, Romance, 2007 New Moon, Stephenie Meyer, Romance, 2007 The Third Gate, Lincoln Child, Fantasy, 2012 1225 Christmas Tree Lane, Debbie Macomber, Romance, 2011 Murder on Astor Place, Victoria Thompson, Mystery, 2009 Heaven is for Real, Todd Burpo, Nonfiction, 2011 15 Seconds, Andrew Gross, Thriller, 2012 Harry Potter and the Chamber of Secrets, J.K. Rowling, Fantasy, 2012 1Q84, Haruki Murakami, Fiction, 2011 The Affair, Lee Child, Mystery, 2011 The Girl With the Dragon Tattoo, Stieg Larsson, Mystery, 2011 Explosive Eighteen, Janet Evanovich, Mystery, 2011 The Help, Kathryn Stockett, Fiction, 2009

A correct program should print out all the Fantasy books:

Dead until Dark, Charlaine Harris, Fantasy, 2001 Inheritance, Christopher Paolini, Fantasy, 2011 The Third Gate, Lincoln Child, Fantasy, 2012 Harry Potter and the Chamber of Secrets, J.K. Rowling, Fantasy, 2012

The data4.o file also contains a pointer named library that points to the first node in the linked list. Thus, one of your first instructions should be:

mov esi, [library]

When you are ready to look at the next node of the linked list, you can just say:

mov esi, [esi+NEXT_OFFSET]


Implementation Notes


Turning in your program

Use the UNIX submit command on the GL system to turn in your project. You should submit 2 files: your assembly language program and a typescript file of a sample run of your program. You do not need to submit the data4.o file.

The UNIX command to do this should look something like:

submit cs313 proj4 fantasy.asm typescript



Last Modified: 22 Jul 2024 11:28:11 EDT by Richard Chang
to Spring 2013 CMSC 313 Homepage