Assembly 在部件中打印链表

Assembly 在部件中打印链表,assembly,linked-list,masm,irvine32,Assembly,Linked List,Masm,Irvine32,我正在尝试打印一个链表,到目前为止它只打印第一个节点,我找不到从下一个节点获取数据的正确方法。这就是我到目前为止所做的,错误在打印循环中,但我不知道如何在堆栈上修复它 INCLUDE Irvine32.inc .data sundaystr byte "today sunday ", 0 mondaystr byte "monday ",0 tuesdaystr byte "tuesday ",0 sunday dword sundaystr dword monday dword 0

我正在尝试打印一个链表,到目前为止它只打印第一个节点,我找不到从下一个节点获取数据的正确方法。这就是我到目前为止所做的,错误在打印循环中,但我不知道如何在堆栈上修复它

INCLUDE Irvine32.inc
.data

sundaystr byte "today sunday  ", 0
mondaystr byte "monday   ",0
tuesdaystr byte "tuesday  ",0

sunday dword sundaystr
dword monday
dword 0

monday dword mondaystr
dword tuesday
dword sunday

tuesday dword tuesdaystr
dword 0
dword monday

.code
main PROC
push sunday

printlist PROC

push edx
push esi
push ebp
mov ebp, esp
mov esi, [ebp+12]
print:
mov edx, esi
call writestring
add esi , 4
mov edx, esi
call writestring

;mov eax , [esi]
;cmp eax , 0
;je done
;jmp print


done:
pop ebp
pop esi
pop edx

printlist endp
main ENDP
END main

如果我理解正确的话,类似C的代码

struct List
{
    const char* name;
    List* first;
    List* second;
};

void PrintList(List* list)
{
    WriteString(list->name);
    if (list->first != NULL)
    {
        WriteString(list->first);
        PrintList(list->first);
    }

    if (list->second != NULL)
    {
        WriteString(list->first);
        PrintList(list->first);
    }
}
重写的x86 asm代码如下所示:

    ; init function frame
    ; esi = List* list
    mov edx, esi         ; load list to edx (points to name)
    call writestring     ; print name

    add esi, 4           ; add 4 to esi, now points to first
    mov edx, esi         ; edx points to first
    cmp edx, 0           ; if (first != NULL)
    je second

    call writestring     ; print first
    call printlist       ; print content of first list
                     ; note that esi gets pushed/popped in the function
second:
    ; do the same again for the List* second
    add esi, 4
    mov edx, esi
    cmp edx, 0
    je end

    call writestring
    call printlist

end:
    ; clear function frame
很可能这个答案不完全正确/你想要什么,但我想你可以从那里搬到别的地方

另外,我建议你广泛使用评论。阅读你正在做的事情真的不容易。它将帮助您自己更清楚地看到代码