How to make a Chained List in Assembly?

Asked

Viewed 813 times

4

I have a college job and I need to make a chained list at Assembly, would like to know how to do the loop to insert all items in the list and keep them connected. The list must contain the data of a video rental company (name of the film, main actor, number of copies of the film...)

This is the code I made so far, it receives the user data and stores in a reserved space (those . space are to reserve memory for each field), what I need is that after entering the first record I can save the position of the next (chain the records).

.section .data

programtitle:       .asciz      "\n Gabriels Library\n\n" # 

asktitle:   .asciz  "\nWrite the title of the book"
askcategory:    .asciz  "\nWrite the category of the book"
askcharacter:   .asciz  "\nWrite the main character"
askyear:    .asciz  "\nWrite the year it was published"
askcopies:  .asciz  "\nWrite the number of copies the library has"

mostratitulo:   .asciz  "\nTitle: %s" # show the title
mostracategoria: .asciz "\nCategory %s" # show category
mostraator: .asciz  "\nCharacter %s" # show character
mostraano:  .asciz  "\nYear %d" #show year
mostracopias:   .asciz  "\nNum of copies: %d" #show number of copies

formstr:    .asciz  "%s"
formint:    .asciz  "%d"
formch: .asciz  "%c"
enter:  .asciz  "\n"

NULL:   .int 0

ttitulo:    .space 44
tano:   .space 4
tcopias: .space 4
tcategoria: .space 24
tator:  .space 44

prox:   .int NULL
naloc:  .int 124

le_dados:
    pushl   %edi

    pushl   $asktitle
    call    printf
    addl    $4, %edi
    call    gets

    popl    %edi
    addl    $44, %edi
    pushl   %edi

    pushl   $askyear
    call    printf
    addl    $4, %esp
    pushl   $formint
    call    scanf
    addl    $4, %esp

    popl    %edi
    addl    $4, %edi
    pushl   %edi

    pushl   formch
    call    scanf
    addl    $4, %esp

    pushl   $askcopies
    call    printf
    addl    $4, %esp
    pushl   $formint
    call    scanf
    addl    $4, %esp

    popl    %edi
    addl    $4, %edi
    pushl   %edi

    pushl   $formch
    call    scanf
    addl    $4, %esp

    pushl   $askcategory
    call    printf
    addl    $4, %esp

    call    gets

    popl    %edi
    addl    $24, %edi
    pushl   %edi

    pushl   $askcharacter
    call    printf
    addl    $4, %esp
    call    gets
    popl    %edi
    addl    $44, %edi
    movl    $NULL, (%edi)

    subl    $124, %edi

    RET
  • 6

    Hi, Abriel, Welcome to [en.so]. Please show the code you are trying to develop. We can help with him, but we can’t make it from scratch for you.

  • 2

    could explain why your code does not work and where you are having more difficulty? understanding Assembly code is no longer easy, when it is of others then it is even worse.

  • this code only receives user data and stores in a reserved space (those . space are to reserve memory for each field) what I need is that after entering the first record I can save the position of the next (chain the records)

  • See if these links help you: http://chortle.ccsu.edu/AssemblyTutorial/Chapter-34/ass34_7.html and http://codereview.stackexchange.com/questions/45999/linux-nasm-assembly-linked-list-implementation

  • I am not a practitioner of Assembly programming, although it was my first language. Using Two Common 'Compression' Techniques, which should certainly use some form that data structure with chaining, as it implements Huffman data compression in Assembly. <br> See the code in the source Huffman.cpp, as it can give you good implementation guidance.

1 answer

4

I recommend you do in C, and when compiling (with GCC) you compile this way

gcc.exe programa.c -o codigo.asm -S

Then the compiler will convert your C code into Assembly, then you can see how it was done!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.