Расчет показателей в сборке AT & T - PullRequest
0 голосов
/ 26 мая 2018

Как бы я поступил, выполняя показатели в сборке 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
...