Last active
September 8, 2019 13:38
-
-
Save priyanshu219/e88cd92ffdfcc231850ca7fcc34d08e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name; --Priyanshu_Garg Enrollment_No.: --18114058 Branch: --CSE | |
mov r0, 1 //i = 1 | |
mov r1, 0 //j = 0 | |
mov r2, 1 //x = 1, Ramanujan number | |
mov r3, 0 //count = 0 | |
.loop1: | |
mov r3, 0 //count = 0 | |
mov r0, 1 //i = 0 | |
.loop2: | |
add r1,r0,1 //j = i + 1 | |
.loop3: | |
mul r4,r0,r0 //r4 = r0*r0, r4=i*i | |
mul r4,r4,r0 //r4 = r4*r0, r4 = i*i*i | |
mul r5,r1,r1 //r5=r1*r1, r5=j*j | |
mul r5,r5,r1 //r5 = r5 * r1, r5 = j*j*j | |
add r6,r4,r5 //r6=r4+r5, r6 = i*i*i + j*j*j | |
cmp r6,r2 //if(i*i*i+j*j*j == x) | |
beq. increase | |
cmp r3,2 //if(count == 2) | |
beq. exit | |
.increase: | |
add r3,r3,1 //count = count+1 | |
add r1,r1,1 //j=j+1 | |
mul r5,r1,r1 //r5=r1*r1 | |
mul r5,r5,r1 //r5 = r5 * r1, r5 = j*j*j | |
add r6,r4,r5 //r6 = i*i*i + j*j*j | |
cmp r2,r6 //if(x >= i*i*i+j*j*j) | |
bgt .loop3 //jump to loop3 | |
beq .loop3 //jump to loop3 | |
add r0,r0,1 //i = i + 1 | |
mul r4,r0,r0 //r4 = r0*r0, r4=i*i | |
mul r4,r4,r0 //r4 = r4*r0, r4 = i*i*i | |
cmp r2,r4 //if(x>i*i*i) | |
bgt .loop2 | |
add r2,r2,1 //x = x + 1 | |
cmp r2,0 //x > 0 | |
bgt. loop1 //jump to loop1 | |
.exit: | |
exit //exit the program | |
//Ramanujan number 1729 is saved in r2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Priyanshu Garg
18114058
CSE