【发布时间】:2017-10-05 01:31:23
【问题描述】:
以下是在 Kip Irvine 的汇编语言 x86 书中找到的链表汇编程序。在 main 中,循环遍历列表并显示所有节点值。程序不使用循环的固定计数器,而是检查尾节点中的空指针并在找到时停止循环。我的问题如下:
(a) 谁能解释一下?它是如何工作的,它是什么意思?
(b) 有人可以解释一下 (ListNode PTR [esi]).NextPtr 吗?这是什么意思?
INCLUDE Irvine32.inc
ListNode STRUCT
NodeData DWORD ?
NextPtr DWORD ?
ListNode ENDS
TotalNodeCount = 15
NULL = 0
Counter = 0
.data
putc macro ptr
push eax
mov al, ptr
call writechar
pop eax
endm
;to use:
;putc 'a'
LinkedList LABEL PTR ListNode
REPEAT TotalNodeCount
Counter = Counter + 1
ListNode <Counter, ($ + Counter * SIZEOF ListNode)>
;struct variables Counter, and ($+Counter*SIZEOF ListNode) being declared
;
ENDM
ListNode <0,0> ; tail node
.code
main PROC
mov esi,OFFSET LinkedList
; Display the integers in the NodeData fields.
NextNode:
; Check for the tail node.
putc 'a'; ->first node, then third node
mov eax,(ListNode PTR [esi]).NextPtr
cmp eax,NULL
je quit
; Display the node data.
putc 'b' ;->fourth node
mov eax,(ListNode PTR [esi]).NodeData
call WriteDec
call Crlf
; Get pointer to next node.
putc 'c' ;->first node
putc 'd' ;->second node
mov esi,(ListNode PTR [esi]).NextPtr
;references a struct using [esi]
jmp NextNode
quit:
exit
main ENDP
END main
【问题讨论】:
标签: assembly struct linked-list x86 masm