Guest User

Untitled

a guest
Apr 18th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int multiplyTwoInteger(int m, int n){
  5. if(n == 0){
  6. return 0;
  7. }
  8. return m + multiplyTwoInteger(m,n-1);
  9. }
  10.  
  11. int main(){
  12. int m = 3, n =5;
  13.  
  14. cout<<multiplyTwoInteger(m,n);
  15.  
  16. return 0;
  17. }
  18.  
  19. **************
  20.  
  21. multiplyTwoInteger:
  22. addi sp,sp,-32
  23. sw x1,24(sp)
  24. sw s0,16(sp)
  25. addi s0,sp,32
  26. addi a5,a0,0
  27. addi a4,a1,0
  28. sw a5,-20(s0)
  29. addi a5,a4,0
  30. sw a5,-24(s0)
  31. lw a5,-24(s0)
  32. addi a5,a5,0
  33. bne a5,x0,.L2
  34. li a5,0
  35. j .L3
  36. .L2:
  37. lw a5,-24(s0)
  38. addi a5,a5,-1
  39. addi a4,a5,0
  40. lw a5,-20(s0)
  41. mv a1,a4
  42. mv a0,a5
  43. j multiplyTwoInteger
  44. mv a5,a0
  45. mv a4,a5
  46. lw a5,-20(s0)
  47. add a5,a5,a4
  48. addi a5,a5,0
  49. .L3:
  50. mv a0,a5
  51. lw ra,24(sp)
  52. lw s0,16(sp)
  53. addi sp,sp,32
  54. jr x1
  55. main:
  56. addi sp,sp,-32
  57. sw x1,24(sp)
  58. sw s0,16(sp)
  59. addi s0,sp,32
  60. li a5,3
  61. sw a5,-20(s0)
  62. li a5,5
  63. sw a5,-24(s0)
  64. lw a4,-24(s0)
  65. lw a5,-20(s0)
  66. addi a1,a4,0
  67. addi a0,a5,0
  68. j multiplyTwoInteger
  69. addi a5,a0,0
  70. addi a1,a5,0
  71. li a5,0
  72. addi a0,a5,0
  73. lw x1,24(sp)
  74. lw s0,16(sp)
  75. addi sp,sp,32
  76. jr x1
  77.  
  78. ***************
  79.  
  80. // C program to get toggle case of a string
  81. #include <stdio.h>
  82.  
  83. // tOGGLE cASE = swaps CAPS to lower
  84. // case and lower case to CAPS
  85. char *toggleCase(char *a)
  86. {
  87. for (int i=0; a[i]!='\0'; i++) {
  88.  
  89. // Bitwise EXOR with 32
  90. a[i] ^= 32;
  91. }
  92.  
  93. return a;
  94. }
  95.  
  96. // Driver Code
  97. int main()
  98. {
  99. char str[] = "CheRrY";
  100. printf("Toggle case: %s\n", toggleCase(str));
  101. printf("Original string: %s", toggleCase(str));
  102. return 0;
  103. }
  104.  
  105.  
  106.  
  107. ****************
  108.  
  109.  
  110. toggleCase(char*):
  111. addi sp,sp,-48
  112. sd s0,40(sp)
  113. addi s0,sp,48
  114. sd a0,-40(s0)
  115. sw zero,-20(s0)
  116. .L3:
  117. lw a5,-20(s0)
  118. ld a4,-40(s0)
  119. add a5,a4,a5
  120. lbu a5,0(a5)
  121. beqz a5,.L2
  122. lw a5,-20(s0)
  123. ld a4,-40(s0)
  124. add a5,a4,a5
  125. lbu a4,0(a5)
  126. lw a5,-20(s0)
  127. ld a3,-40(s0)
  128. add a5,a3,a5
  129. xori a4,a4,32
  130. andi a4,a4,0xff
  131. sb a4,0(a5)
  132. lw a5,-20(s0)
  133. addiw a5,a5,1
  134. sw a5,-20(s0)
  135. j .L3
  136. .L2:
  137. ld a5,-40(s0)
  138. mv a0,a5
  139. ld s0,40(sp)
  140. addi sp,sp,48
  141. jr ra
  142. .LC0:
  143. .string "Toggle case: %s\n"
  144. .LC1:
  145. .string "Original string: %s"
  146. main:
  147. addi sp,sp,-32
  148. sd ra,24(sp)
  149. sd s0,16(sp)
  150. addi s0,sp,32
  151. li a5,1382379520
  152. addiw a5,a5,-1981
  153. sw a5,-24(s0)
  154. li a5,24576
  155. addiw a5,a5,-1678
  156. sh a5,-20(s0)
  157. sb zero,-18(s0)
  158. addi a5,s0,-24
  159. mv a0,a5
  160. call toggleCase(char*)
  161. mv a5,a0
  162. mv a1,a5
  163. lui a5,%hi(.LC0)
  164. addi a0,a5,%lo(.LC0)
  165. call printf
  166. addi a5,s0,-24
  167. mv a0,a5
  168. call toggleCase(char*)
  169. mv a5,a0
  170. mv a1,a5
  171. lui a5,%hi(.LC1)
  172. addi a0,a5,%lo(.LC1)
  173. call printf
  174. li a5,0
  175. mv a0,a5
  176. ld ra,24(sp)
  177. ld s0,16(sp)
  178. addi sp,sp,32
  179. jr ra
Add Comment
Please, Sign In to add comment