Search code examples
assemblymasmmasm32

For MASM, what kind of output is this asking for?


From Kip Irvine's Intel x86 Assembly Language

I'm confused as to what this problem is asking for as an output. Can anyone clarify? You do not need to solve the problem. I just need help understanding what it is asking for!


Solution

  • What you're seeing there is a linked list where:

    • 1 is the starting index;
    • each character is the payload;
    • each link is the next pointer.

    It may be better to think of it as:

    start = 1
    index:    0  1  2  3  4  5  6  7
    char:     H  A  C  E  B  D  F  G
    next:     0  4  5  6  2  3  7  0
    

    and realise that:

    • The starting index of 1 gives you the character A and a link of 4.
    • That index of 4 gives you the character B and a link of 2.
    • That index of 2 gives you the character C and a link of 5.
    • That index of 5 gives you the character D and a link of 3.
    • And so on.

    Rearranging them sorted on list (following start/next) order gives you:

    start = 1
    index:    1  4  2  5  3  6  7  0
    char:     A  B  C  D  E  F  G  H
    next:     4  2  5  3  6  7  0  0
    

    So it's effectively the linked list:

    A -> B -> C -> D -> E -> F -> G -> H -> H -> H ...
    

    The expected result should just be the linked list in order (ABCDEFGH) copied to a new array but, interestingly enough, H points to itself rather than some special NULL value, so you will have to detect that as a special case.