问题描述
.global _start
.section .text
_start:
movq a,%rax
movq b,%rbx
imul %rbx,%rax
cmp %rbx,%rax
je gcd_calculated
ja l1
sub %rax,%rbx
jmp _start
l1:
sub %rbx,%rax
jmp _start
gcd_calculated:
div %rax
movq %rax,(c)
a,b
是四边形,我需要计算它们的lcm,我需要将结果分配给c
通常,我中继lcm = (a*b)/gcd
,因此我将a * b存储在%rax
中,然后计算gcd,它将存储在%eax中,最后在它们之间进行划分。
解决方法
就像1201ProgramAlarm所说,您正在计算和比较循环的每次迭代中a
和b
的原始值。如果要遵循当前的方法,则每次循环之前都必须将这些值存储在内存中。
实际上,我要做的只是先进行gcd计算,然后最后计算(a*b)/gcd
。
_start:
movq a(%rip),%rbx
movq b(%rip),%rcx
gcd:
cmp %rbx,%rcx
je gcd_calculated
ja l1
sub %rcx,%rbx
jmp gcd
l1:
sub %rbx,%rcx
jmp gcd
gcd_calculated:
movq a(%rip),%rax
xor %rdx,%rdx
div %rbx
imul b(%rip),%rax
movq %rax,c(%rip)
,
App\Entities\Category {#2114 ▼
...
#attributes: array:11 [▶]
#original: array:11 [▶]
...
#relations: array:1 [▼
"childrenCategories" => Illuminate\Database\Eloquent\Collection {#2118 ▼
#items: array:4 [▼
0 => App\Entities\Category {#2133 ▶}
1 => App\Entities\Category {#2134 ▶}
2 => App\Entities\Category {#2135 ▼
...
#attributes: array:11 [▶]
#original: array:11 [▶]
...
#relations: array:1 [▼
"categories" => Illuminate\Database\Eloquent\Collection {#2138 ▼
#items: array:1 [▼
0 => App\Entities\Category {#2157 ▼
...
#attributes: array:11 [▶]
#original: array:11 [▶]
...
#relations: []
...
}
]
}
]
...
}
3 => App\Entities\Category {#2136 ▶}
]
}
]
...
}