- 已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
12小时前关门了。
Improve this question
建立一个有向图,给定n =节点数(〈= 100),N条线,其中将是每个mod的键数,M条线与每个节点的键节点。例如:
4//节点数
2//节点0有2个键(1和2)
2//节点1有2个键(2和3)
1//节点2有2个键(有3个键)
0//节点3有2个键(没有键)
1//债券
节点0的2//
2//债券
节点1的3//
3//节点的连接2
给定此输入,输出应为:
0 1 1
0 0 1 1
0 0 0 1
0 0 0 0
我在asm att中编写了以下代码:
.data
n: .space 4
v: .space 400
i: .space 4
m: .space 400
Leg: .space 4
columnIndex: .space 4
lineIndex: .space 4
formatScanf: .asciz "%ld"
formatPrintf: .asciz "%ld "
newLine: .asciz "\n"
.text
.global main
main:
pusha
pushl $n
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
popa
xor %ecx, %ecx
lea v, %esi
forcitire: (=this function creates a vector for the the number of bonds)
cmp %ecx, n
je afisare
pusha
pushl $i
pushl $formatScanf
call scanf
popl %edx
popl %edx
popa
movl i, %eax
mov %eax, (%esi, %ecx, 4)
inc %ecx
jmp forcitire
afisare: (=resets ecx)
xor %ecx, %ecx
et_constructie: (=construct the matrix)
cmp %ecx, n
je et_rest
mov (%esi, %ecx, 4), %ebx
et_leg:
cmp $0, %ebx
je et_inc
pusha
pushl $Leg
pushl $formatScanf
call scanf
popl %edx
popl %edx
popa
movl $0, %edx
movl %ebx, %eax
mull n
addl Leg, %eax
lea m, %edi
movl $1 , (%edi, %eax, 4)
dec %ebx
jmp et_leg
et_inc:
incl %ecx
jmp et_constructie
et_rest: (resets ecx)
xor %ecx, %ecx
et_afis_matr: (=prints the graph matrix)
movl $0, lineIndex
for_lines:
movl lineIndex, %ecx
cmp %ecx, n
je et_exit
movl $0, columnIndex
for_columns:
movl columnIndex, %ecx
cmp %ecx, n
je cont
movl lineIndex, %eax
movl $0, %edx
mull n
addl columnIndex, %eax
lea m, %edi
movl (%edi, %eax, 4), %ebx
pusha
pushl %ebx
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
popa
pusha
pushl $0
call fflush
popl %ebx
popa
incl columnIndex
jmp for_columns
cont: (=goes to the next line)
movl $4, %eax
movl $1, %ebx
movl $newLine, %ecx
movl $2, %edx
int $0x80
incl lineIndex
jmp for_lines
et_exit:
movl $1, %eax
movl $0, %ebx
int $0x80
代码打印
0 0 0 0
0 0 1 1
0 1 1
0 0 0 0
1条答案
按热度按时间6qftjkof1#
所以我把ebx移到了eax中,而不是ecx移到了eax中,这就解决了我的问题,在ebx中是特定节点的键数,ecx是与节点数比较的指数,节点数是我在矩阵中得到正确指数所需要的。