Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int multiplyTwoInteger(int m, int n){
- if(n == 0){
- return 0;
- }
- return m + multiplyTwoInteger(m,n-1);
- }
- int main(){
- int m = 3, n =5;
- cout<<multiplyTwoInteger(m,n);
- return 0;
- }
- **************
- multiplyTwoInteger:
- addi sp,sp,-32
- sw x1,24(sp)
- sw s0,16(sp)
- addi s0,sp,32
- addi a5,a0,0
- addi a4,a1,0
- sw a5,-20(s0)
- addi a5,a4,0
- sw a5,-24(s0)
- lw a5,-24(s0)
- addi a5,a5,0
- bne a5,x0,.L2
- li a5,0
- j .L3
- .L2:
- lw a5,-24(s0)
- addi a5,a5,-1
- addi a4,a5,0
- lw a5,-20(s0)
- mv a1,a4
- mv a0,a5
- j multiplyTwoInteger
- mv a5,a0
- mv a4,a5
- lw a5,-20(s0)
- add a5,a5,a4
- addi a5,a5,0
- .L3:
- mv a0,a5
- lw ra,24(sp)
- lw s0,16(sp)
- addi sp,sp,32
- jr x1
- main:
- addi sp,sp,-32
- sw x1,24(sp)
- sw s0,16(sp)
- addi s0,sp,32
- li a5,3
- sw a5,-20(s0)
- li a5,5
- sw a5,-24(s0)
- lw a4,-24(s0)
- lw a5,-20(s0)
- addi a1,a4,0
- addi a0,a5,0
- j multiplyTwoInteger
- addi a5,a0,0
- addi a1,a5,0
- li a5,0
- addi a0,a5,0
- lw x1,24(sp)
- lw s0,16(sp)
- addi sp,sp,32
- jr x1
- ***************
- // C program to get toggle case of a string
- #include <stdio.h>
- // tOGGLE cASE = swaps CAPS to lower
- // case and lower case to CAPS
- char *toggleCase(char *a)
- {
- for (int i=0; a[i]!='\0'; i++) {
- // Bitwise EXOR with 32
- a[i] ^= 32;
- }
- return a;
- }
- // Driver Code
- int main()
- {
- char str[] = "CheRrY";
- printf("Toggle case: %s\n", toggleCase(str));
- printf("Original string: %s", toggleCase(str));
- return 0;
- }
- ****************
- toggleCase(char*):
- addi sp,sp,-48
- sd s0,40(sp)
- addi s0,sp,48
- sd a0,-40(s0)
- sw zero,-20(s0)
- .L3:
- lw a5,-20(s0)
- ld a4,-40(s0)
- add a5,a4,a5
- lbu a5,0(a5)
- beqz a5,.L2
- lw a5,-20(s0)
- ld a4,-40(s0)
- add a5,a4,a5
- lbu a4,0(a5)
- lw a5,-20(s0)
- ld a3,-40(s0)
- add a5,a3,a5
- xori a4,a4,32
- andi a4,a4,0xff
- sb a4,0(a5)
- lw a5,-20(s0)
- addiw a5,a5,1
- sw a5,-20(s0)
- j .L3
- .L2:
- ld a5,-40(s0)
- mv a0,a5
- ld s0,40(sp)
- addi sp,sp,48
- jr ra
- .LC0:
- .string "Toggle case: %s\n"
- .LC1:
- .string "Original string: %s"
- main:
- addi sp,sp,-32
- sd ra,24(sp)
- sd s0,16(sp)
- addi s0,sp,32
- li a5,1382379520
- addiw a5,a5,-1981
- sw a5,-24(s0)
- li a5,24576
- addiw a5,a5,-1678
- sh a5,-20(s0)
- sb zero,-18(s0)
- addi a5,s0,-24
- mv a0,a5
- call toggleCase(char*)
- mv a5,a0
- mv a1,a5
- lui a5,%hi(.LC0)
- addi a0,a5,%lo(.LC0)
- call printf
- addi a5,s0,-24
- mv a0,a5
- call toggleCase(char*)
- mv a5,a0
- mv a1,a5
- lui a5,%hi(.LC1)
- addi a0,a5,%lo(.LC1)
- call printf
- li a5,0
- mv a0,a5
- ld ra,24(sp)
- ld s0,16(sp)
- addi sp,sp,32
- jr ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement