我通过比较交流程序与其程序集等效来学习程序集.
这是代码.
.file "ex3.c"
.section .rodata
.LC0:
.string "I am %d years old.\n"
.LC1:
.string "I am %d inches tall.\n"
.text
.globl main
.type main, @function
main:
pushl %ebp //establish stack frame//
movl %esp, %ebp //move esp into ebp, all contents saved down stack//
andl $-16, %esp //16 from esp for local var space//
subl $32, %esp//stack frame reserving - 32 bytes//
movl $10, 24(%esp)
movl $72, 28(%esp)
movl 24(%esp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl …Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法来查找列表列表中给定节点的所有邻居.该数组如下所示:
0,2,4,1,6,0,0
2,0,0,0,5,0,0
4,0,0,0,5,5,0
1,0,0,0,1,1,0
6,5,0,1,0,5,5
0,0,5,1,5,0,0
0,0,0,0,5,0,0
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码是:
#!/usr/bin/python
#holds all source nodes
source = []
#read in and store the matrix
def create_matrix(file):
with open('network.txt') as f:
Alist = []
for line in f:
part = []
for x in line.split(','):
part.append(int(x))
Alist.append(part)
return Alist
def check_neighbours(Alist):
i = iter(Alist)
item = i.next()
source.append(item)
print source
file = ("F:/media/KINGSTON/Networking/network.txt")
Alist = create_matrix(file)
check_neighbours(Alist)
Run Code Online (Sandbox Code Playgroud)
显然这只输出矩阵的第一行,但我想要一些不同的东西.例如,我将从节点[0,0]开始,它是0,然后找到[0,1]和[1,0].但是如果我不在矩阵的边缘,我还需要查看3x3半径.我知道如何找到当前节点右侧的下一个邻居,但我真的不确定如何找到包含对角节点的节点旁边的任何内容.