Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this programming assignment you will develop three assembly language procedu

ID: 3841199 • Letter: F

Question

For this programming assignment you will develop three assembly language procedures that will be called from C. The C module is given to you. You will provide the assembly module containing the three procedures.

You will create and use a structure called BookNode that can be used to create a linked list of nodes. The BookNode structure should contain the following fields:

StockNum - A 32-bit integer initialized to zero, sequentially initialized starting at 1001

Title - A string pointer initialized to a constant value of NULL (0)

ISBN10 - A string pointer initialized to a constant value of NULL (0)

Year - A 32-bit integer containing the year, uninitialized

Month - A 32-bit integer containing the month, uninitialized

Day - A 32-bit integer containing the day, uninitialized

NextPtr - A pointer to the next node initialized to a constant value of NULL (0)

The following shows an equivalent C structure:

Your assembly version of the structure should be compatible with the above such that te member variables can be accessed either from C or assembly.

Use a REPEAT block to create 30 BookNode structures in memory in your assembly module. This should go into the .data section of the module.

The C prototype for the first assembly procedure is shown below.

int newBook(int stockNum, char* title, char* isbn, int year, int month, int day);

newBook will find the node in the list with the given stock number, then set the member values to those values that were passed to the procedure.

The newBook procedure should use a macro called mNewBook that sets the associated values for the node corresponding to the designated stock number. mNewBook should perform the search for the node containing the designated stock number, then set the members accordingly.

Use conditional-assembly directives within the mNewBook macro to verify that none of the parameters are blank.

The newBook procedure should return a -1 if the node could not be found and 0 if it was successfully found.

The C prototype for the second procedure is shown below.

struct BookNode* getBook(int stockNum);

getBook will return a pointer to the node containing the stock number. The getBook procedure should return NULL (0) if the node could not be found.

Create a macro called mGetBook that finds the node with the designated stock number and returns a pointer to the node needed for the procedure.

The C prototype for the third procedure is shown below.

int deleteBook(int stockNum);

The deleteBook procedure should remove the node containing the stock number from the list. Of course the deleted node cannot be removed from memory since that was defined in static memory (the data segment). The removal can be done by setting the pointer for the previous node to point to the node following the one being deleted. A macro called mDeleteBook should be invoked to do the work of removing the node from the linked list. C code that removes an item looks something like the following:

#include <stdio.h>

// The matching C version of the structure
struct BookNode {
   int stockNum;
   char* bookTitle;
   char *isbn10;
   int year;
   int month;
   int day;
   struct BookNode* nextPtr;
};

// C prototypes for the functions written in assembly language
// newBook will cause new information to be added to the linked list for the node having the specified stockNum
int newBook(int stockNum, char* title, char* isbn, int year, int month, int day);
// getBook will find the node having the specified stock number and return a pointer to it
struct BookNode* getBook(int stockNum);
// deleteBook will delete the node having the specified stock number from the linked list
int deleteBook(int stockNum);

// Main -------------------------------------------------------------------
int main()
{
   int ret;
   struct BookNode* bookNodePtr;

   // Add a book to the linked list
   ret = newBook(1005, "Assembly Language for x86 Processors (7th Edition)", "0133769402", 2017, 5, 8);
   if (ret < 0) {
       printf("Could not add the new book for stock number %d ", 1005);
       return -1;
   }

   // Now get a pointer to the node
   bookNodePtr = getBook(1005);

   // Exit if the node was not found
   if (bookNodePtr == NULL) {
       printf("Could not find the book for stock number %d ", 1005);
       return -1;
   }

   // Show the member values
   printf("Book title: %s ", bookNodePtr->bookTitle);
   printf("ISBN: %s ", bookNodePtr->isbn10);
   printf("Date: %d/%d/%d ", bookNodePtr->month, bookNodePtr->day, bookNodePtr->year);

   // Delete the book we added
   ret = deleteBook(1005);
   if (ret < 0) {
       printf("Could not delete the book for stock number %d ", 1005);
       return -1;
   }

   return 0;
}

Explanation / Answer

please find the below codes:::::

.file        1 ""

.section .mdebug.abi32

.previous

.gnu_attribute 4, 1

.abicalls

.rdata

.align     2

$LC0:

.ascii      "Assembly Language for x86 Processors (7th Edition)"

.align     2

$LC1:

.ascii      "0133769402"

.align     2

$LC2:

.ascii      "Could not add the new book for stock number %d "

.align     2

$LC3:

.ascii      "Could not find the book for stock number %d "

.align     2

$LC4:

.ascii      "Book title: %s "

.align     2

$LC5:

.ascii      "ISBN: %s "

.align     2

$LC6:

.ascii      "Date: %d/%d/%d "

.align     2

$LC7:

.ascii      "Could not delete the book for stock number %d "

.text

.align     2

.globl     main

$LFB0 = .

.set        nomips16

.ent        main

.type     main, @function

main:

.frame $fp,48,$31                           # vars= 8, regs= 2/0, args= 24, gp= 8

.mask    0xc0000000,-4

.fmask 0x00000000,0

.set        noreorder

.cpload $25

.set        nomacro

addiu     $sp,$sp,-48

$LCFI0:

sw          $31,44($sp)

$LCFI1:

sw          $fp,40($sp)

movz     $31,$31,$0

$LCFI2:

move    $fp,$sp

$LCFI3:

.cprestore           24

li              $2,5                                        # 0x5

sw          $2,16($sp)

li              $2,8                                        # 0x8

sw          $2,20($sp)

li              $4,1005                                 # 0x3ed

lw           $2,%got($LC0)($28)

nop

addiu     $5,$2,%lo($LC0)

lw           $2,%got($LC1)($28)

nop

addiu     $6,$2,%lo($LC1)

li              $7,2017                                 # 0x7e1

lw           $2,%call16(_Z7newBookiPcS_iii)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

sw          $2,36($fp)

lw           $2,36($fp)

nop

bgez      $2,$L2

nop

lw           $2,%got($LC2)($28)

nop

addiu     $4,$2,%lo($LC2)

li              $5,1005                                 # 0x3ed

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

li              $2,-1                                      # 0xffffffffffffffff

b             $L3

nop

$L2:

li              $4,1005                                 # 0x3ed

lw           $2,%call16(_Z7getBooki)($28)

nop

move    $25,$2

jalr          $25

op

lw           $28,24($fp)

sw          $2,32($fp)

lw           $2,32($fp)

nop

bne        $2,$0,$L4

nop

lw           $2,%got($LC3)($28)

nop

addiu     $4,$2,%lo($LC3)

li              $5,1005                                 # 0x3ed

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

li              $2,-1                                      # 0xffffffffffffffff

b             $L3

nop

$L4:

lw           $2,32($fp)

nop

lw           $2,4($2)

lw           $3,%got($LC4)($28)

nop

addiu     $4,$3,%lo($LC4)

move    $5,$2

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

lw           $2,32($fp)

nop

lw           $2,8($2)

lw           $3,%got($LC5)($28)

nop

addiu     $4,$3,%lo($LC5)

move    $5,$2

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

lw           $2,32($fp)

nop

lw           $5,16($2)

lw           $2,32($fp)

nop

lw           $3,20($2)

lw           $2,32($fp)

nop

lw           $2,12($2)

lw           $4,%got($LC6)($28)

nop

addiu     $4,$4,%lo($LC6)

move    $6,$3

move    $7,$2

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

li              $4,1005                                 # 0x3ed

lw           $2,%call16(_Z10deleteBooki)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

sw          $2,36($fp)

lw           $2,36($fp)

nop

bgez      $2,$L5

nop

lw           $2,%got($LC7)($28)

nop

addiu     $4,$2,%lo($LC7)

li              $5,1005                                 # 0x3ed

lw           $2,%call16(printf)($28)

nop

move    $25,$2

jalr          $25

nop

lw           $28,24($fp)

li              $2,-1                                      # 0xffffffffffffffff

b             $L3

nop

$L5:

move    $2,$0

$L3:

move    $sp,$fp

lw           $31,44($sp)

lw           $fp,40($sp)

addiu     $sp,$sp,48

j               $31

nop

.set        macro

.set        reorder

.end       main

$LFE0:

.size       main, .-main

.section                .eh_frame,"aw",@progbits

$Lframe1:

.4byte   $LECIE1-$LSCIE1

$LSCIE1:

.4byte   0x0

.byte     0x1

.globl     __gxx_personality_v0

.ascii      "zP"

.uleb128 0x1

.sleb128 -4

.byte     0x1f

.uleb128 0x5

.byte     0x0

.4byte   __gxx_personality_v0

.byte     0xc

.uleb128 0x1d

.uleb128 0x0

.align     2

$LECIE1:

$LSFDE1:

.4byte   $LEFDE1-$LASFDE1

$LASFDE1:

.4byte   $LASFDE1-$Lframe1

.4byte   $LFB0

.4byte   $LFE0-$LFB0

.uleb128 0x0

.byte     0x4

.4byte   $LCFI0-$LFB0

.byte     0xe

.uleb128 0x30

.byte     0x4

.4byte   $LCFI2-$LCFI0

.byte     0x11

.uleb128 0x1e

.sleb128 2

.byte     0x11

.uleb128 0x1f

.sleb128 1

.byte     0x4

.4byte   $LCFI3-$LCFI2

.byte   0xd

.uleb128 0x1e

.align     2

$LEFDE1:

.ident    "GCC: (Debian 4.4.5-8) 4.4.5"

   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote