我如何在AT& T程序集中进行指数操作,例如x ^ y,x = 3,y = 10?
假设r14的值为3. r15的值为10.其中r14 = x,r15 = y。
我可以这样做来计算x ^ y的指数吗?如果不是如何计算AT& T组件中的指数?
.globl functionWithItems
functionWithItems:
//Do some stuff that I want here.
//I need to x ^ y
jmp .power
.power:
imulq %r14, %r14
dec %r15
cmpq $-1, %r15
jne .power
jmp .continueOtherPartsOfProgram
.continueOtherPartsOfProgram:
//Do some stuff after doing the power. r14 should now contain x ^ y.
ret
修改代码后:
.globl functionWithItems
functionWithItems:
//Do some stuff that I want here.
//I need to x ^ y
cmpq $0, %r15
je .zeroValue
movq %r14, %rbx
cmpq $2, %r15
jge .numberTimes
jmp .continueOtherPartsOfProgram
.zeroValue:
movq $1, %rbx
jmp .continueOtherPartsOfProgram
.numberTimes:
dec %r15
jmp .power
.power:
imulq %r14, %rbx
dec %r15
cmpq $0, %r15
jne .power
jmp .continueOtherPartsOfProgram
.continueOtherPartsOfProgram:
//Do some stuff after doing the power. r14 should now contain x ^ y.
ret