Директива PROC
ищет в стеке аргументы даже при использовании ML64.exe. Но «Соглашение о вызовах Microsoft x64» передает аргументы в регистрах. Вы можете сохранить регистры в процедуре в так называемом теневом пространстве или - лучше - работать напрямую с регистрами:
intadd PROC
mov eax, ecx
add eax, edx
ret
intadd ENDP
Кстати: DWORD
эквивалентно unsigned int
. Итак, адаптируйте строку формата: printf("%u", intadd(1,1));
. Или используйте тип C int
в файле C.
Расширение Nick Stinemates ответ
class Node(object):
def __init__(self):
self.data = None
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def prepend_node(self, data):
new_node = Node()
new_node.data = data
new_node.next = self.head
self.head = new_node
def append_node(self, data):
new_node = Node()
new_node.data = data
current = self.head
while current.next:
current = current.next
current.next = new_node
def reverse(self):
""" In-place reversal, modifies exiting list"""
previous = None
current_node = self.head
while current_node:
temp = current_node.next
current_node.next = previous
previous = current_node
current_node = temp
self.head = previous
def search(self, data):
current_node = self.head
try:
while current_node.data != data:
current_node = current_node.next
return True
except:
return False
def display(self):
if self.head is None:
print("Linked list is empty")
else:
current_node = self.head
while current_node:
print(current_node.data)
current_node = current_node.next
def list_length(self):
list_length = 0
current_node = self.head
while current_node:
list_length += 1
current_node = current_node.next
return list_length
def main():
linked_list = LinkedList()
linked_list.prepend_node(1)
linked_list.prepend_node(2)
linked_list.prepend_node(3)
linked_list.append_node(24)
linked_list.append_node(25)
linked_list.display()
linked_list.reverse()
linked_list.display()
print(linked_list.search(1))
linked_list.reverse()
linked_list.display()
print("Lenght of singly linked list is: " + str(linked_list.list_length()))
if __name__ == "__main__":
main()
Принятый ответ довольно сложен. Вот более стандартный дизайн:
L = LinkedList()
L.insert(1)
L.insert(1)
L.insert(2)
L.insert(4)
print L
L.clear()
print L
Это простой класс LinkedList
, основанный на простом дизайне C ++ и Глава 17: Связанные списки , как рекомендовано Томасом Уотнедалом .
class Node:
def __init__(self, value = None, next = None):
self.value = value
self.next = next
def __str__(self):
return 'Node ['+str(self.value)+']'
class LinkedList:
def __init__(self):
self.first = None
self.last = None
def insert(self, x):
if self.first == None:
self.first = Node(x, None)
self.last = self.first
elif self.last == self.first:
self.last = Node(x, None)
self.first.next = self.last
else:
current = Node(x, None)
self.last.next = current
self.last = current
def __str__(self):
if self.first != None:
current = self.first
out = 'LinkedList [\n' +str(current.value) +'\n'
while current.next != None:
current = current.next
out += str(current.value) + '\n'
return out + ']'
return 'LinkedList []'
def clear(self):
self.__init__()