Нажмите для описания вопроса
Этот код реализован с использованием сборки ARM, и есть основная функция, вызывающая функцию магического числа, которая вводит 'Yusuf Ozturk'
/*
* AssemblyFunctions.S
*
*/
.global upper
.text
upper:
bx lr
.global computeMagicNumber
.text
computeMagicNumber:
MOV R1, #0 //The value gets i = 0
MOV R3, #0 //Sets the sum to 0
MOV R5, #0 //R5 holds the value of Magic Number
LOOP:
LDR R0, [R2, R1] //R2 gets the string inputted by the user at the index i
CMP R2, #0 //If the string is empty then...
BEQ END //...the program is branched to end
ADD R1, #1 // Increments the value of i by 1
MUL R4, R2, R1 //R4 gets the value of the string indexed at i multiplied by i+1
ADD R3, R3, R4 //The sum is added by the value above (R4)
B LOOP //Returns to top of loop
END:
AND R3, #1000 //Sum is divided by 1001 and gets the remainder
MOV R0, R3 //Value is returned
bx lr