SHARE
TWEET

Untitled

a guest Jan 25th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     n: .word 4
  3.  
  4. .text
  5.  
  6. main:
  7.     la $a0, n
  8.     lw $a0, 0($a0)
  9.    
  10.     addi $sp, $sp, -8
  11.     sw $ra, 0($sp)
  12.     sw $a0, 4($sp)
  13.    
  14.     jal T
  15.    
  16.     add $a0, $v0, $0
  17.     addi $v0, $0, 1
  18.     syscall
  19.    
  20.     lw $ra, 0($sp)
  21.     lw $a0, 4($sp)
  22.     addi $sp, $sp, 8
  23.     jr $ra
  24.    
  25.  
  26. T:
  27.     addi $t1, $0, 3
  28.     slt $t1, $a0, $t1
  29.     beq $t1, $0, Else
  30.     add $v0, $0, 1
  31.     jr $ra
  32.    
  33.     Else:
  34.         addi $sp, $sp, -20
  35.         sw $ra, 0($sp)
  36.         sw $s0, 4($sp)
  37.         sw $s1, 8($sp)
  38.         sw $s2, 12($sp)
  39.         sw $s3, 16($sp)
  40.  
  41.         add $s3, $0, $0
  42.         addi $a0, $a0, -1       # n -= 1
  43.         add $s1, $a0, $0
  44.         For:
  45.             add $s0, $s3, $0
  46.             addi $s3, $s3, 1
  47.             add $a0, $s0, $0
  48.            
  49.             jal T
  50.             mult $v0, $s0
  51.             mflo $t0
  52.             add $s2, $s2, $t0
  53.             bne $s0, $s1, For
  54.        
  55.         add $v0, $0, $s2
  56.        
  57.         lw $ra, 0($sp)
  58.         lw $s0, 4($sp)
  59.         lw $s1, 8($sp)
  60.         lw $s2, 12($sp)
  61.         lw $s3, 16($sp)
  62.         addi $sp, $sp, 20
  63.         jr $ra
  64.        
  65. Versione C:
  66.  
  67. #include <stdio.h>
  68.  
  69. int c(int n, int count)
  70. {
  71.     if(n<3){return 1;}
  72.     for(int x=0; x<=n-1; x++)
  73.     {
  74.         count += x*c(x, count);
  75.     }
  76.     return count;
  77. }
  78.  
  79. int main()
  80. {
  81.     int n = 4;
  82.     printf("%d", c(n, 0));
  83.     return 0;
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top