Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Architettura degli elaboratori e delle reti > Ricorsione MIPS
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
LOSTMAN
.novellino.

User info:
Registered: Feb 2009
Posts: 7 (0.00 al dì)
Location:
Corso:
Anno:
Time Online: 1:25:50 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Question Ricorsione MIPS

salve raga sono disperato qualcuno potrebbe dirmi le regole base per fare una funzione ricorsiva
ovviamente
sono casi base
e ricorsione
ma come si implementano in assembler mips
ad esempio questa come se fa
function recur(n:integer,z:integer):integer;
var m:integer;
begin
x=resto di n/5
if (x<0)
then recur :=1
else m:=call(z)
recur:=(recur(m)+recur(x))
end;

:?:?:?:?:?:?

17-02-2009 20:33
Click Here to See the Profile for LOSTMAN Click here to Send LOSTMAN a Private Message Find more posts by LOSTMAN Add LOSTMAN to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
LOSTMAN
.novellino.

User info:
Registered: Feb 2009
Posts: 7 (0.00 al dì)
Location:
Corso:
Anno:
Time Online: 1:25:50 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

nessuno ci riesce

20-02-2009 00:16
Click Here to See the Profile for LOSTMAN Click here to Send LOSTMAN a Private Message Find more posts by LOSTMAN Add LOSTMAN to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lordghost
Black Lord

User info:
Registered: Oct 2005
Posts: 232 (0.03 al dì)
Location: Milan
Corso: Informatica
Anno: 3
Time Online: 2 Days, 9:48:49 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ti posto quello che avevo fatto io. calcola se non ricordo male il fattoriale di n... ancora oggi non capisco perchè mi sia stato valutato solo 26?!?!?:evil:
È abbastanza commentato, quindi spero ti possa essere utile. Non mi chiedere come funziona perchè non mi ricordo :D

PHP:

# programma per il calcolo ricorsivo di n! 

.data
msgn
:     .asciiz "Inserire n:"
msgk:     .asciiz "Inserire k:"
msgr:     .asciiz "Risultato:"
msgx:     .asciiz "\nPremere qualsiasi tasto per uscire, c per continuare"
msgend:    .asciiz "\nProgramma terminato"
msgreb:    .asciiz "\n\nRiavvio del programma\n"
chr :   .asciiz " "  # buffer per la lettura del carattere di uscita

.text
.globl main

main
:

# Lettura di n
letturan:
  
li $v04           # $v0 codice della print_string
  
la $a0msgn      # $a0 indirizzo della stringa
  
syscall             # stampa della stringa

  
li $v05           # $v0 codice della read_int
  
syscall             # legge l’intero n e lo carica in $v0

  
bltz $v0letturan
  move $s0
$v0

# Lettura di k
letturak:
  
li $v04           # $v0 codice della print_string
  
la $a0msgk      # $a0 indirizzo della stringa
  
syscall             # stampa della stringa

  
li $v05           # $v0 codice della read_int
  
syscall             # legge l’intero n e lo carica in $v0

  
bltz $v0letturak
  move $s1
$v0




# Calcolo della funzione
  
move $a0$s0        # a0 = n
  
move $a1$s1        # a1 = k
  
jal  s
  abs $s0
$v0        # s0 = s(n,k)
    
# Stampa del risultato
    
li $v04        # codice della print_int
    
la $a0msgr
    syscall

    move $a0
$s0    # a0 = s0 = s(n,k)
    
li $v01        # codice della print_int
    
syscall


#uscire o continuare
  
li $v04           # $v0 codice della print_string
  
la $a0msgx      # $a0 indirizzo della stringa
  
syscall             # stampa della stringa

  
la $a0chr          # $a0 indirizzo del buffer
  
li $a12
  li $v0
8           # $v0 codice della read_int
  
syscall             # legge l’intero n e lo carica in $v0

  #move $a0, $v0
  
lb $a0chr        #0x20200063 and
  #li $t0, 255        #0x000000FF =
  #and $a0, $a0, $t0    #0x00000063

  
bne $a099esci

    li $v0
4        # codice della print_int
    
la $a0msgreb
    syscall   
    j letturan


# Termine del programma    
esci:
    
li $v04        # codice della print_int
    
la $a0msgend
    syscall

    li $v0
10         # $v0 codice della exit
    
syscall        # esce dal programma




 #*************************************************
********
#            PROCEDURA Stirling
 #*************************************************
********

s:
  
addi $sp$sp,-24          # alloca stack
  
sw   $ra20($sp)        # salvo return address
  
sw   $a016($sp)        # salvo l’argomento n
  
sw   $a112($sp)        # salvo l’argomento k
  
sw   $t08($sp)        # salvo s(n-1, k-1)
  
sw   $t14($sp)        # salvo s(n-1, k)
  
sw   $t20($sp)        # salvo 1

  #debug print (stampa n)
  #  li $v0, 1
  #  syscall

#casi 1-2

  
bnez $a1caso3    #k!=0
  
bnez $a0caso2    #n!=0
  #caso1
    
li $v01
    j end
  
#caso2
  
caso2:
    
blez $a0caso3
    li $v0
0
    j end
  caso3
:
    
bge $a0$a1caso4
    
#caso3
      
li $v00
      j end
  
#caso4
  
caso4:
    
addi $a0, -1        # n = n-1
    
addi $a1, -1        # k = k-1
    
jal s
    move $t0
$v0        # t0 = s(n-1, k-1)

    
lw $a112($sp)        # ripristina a1 = k
    
jal s
    mul $t1
$a0$v0        # t1 = (n-1)*s(n-1, k)

    
sub $v0$t0$t1        # il risultato sta in v0

end:
  
lw   $t20($sp)        # ripristino t2
  
lw   $t14($sp)        # ripristino t1
  
lw   $t08($sp)        # ripristino t0
  
lw   $a112($sp)        # ripristino parametro1
  
lw   $a016($sp)        # ripristino parametro2
  
lw   $ra20($sp)        # ripristino return address
  
addi $sp$sp24        # dealloca stack
  
jr   $ra            # ritorno al chiamante

Attachment: prog.asm.txt
This has been downloaded 16 time(s).

__________________
My 3D blog: http://www.webgl.it

21-02-2009 09:53
Click Here to See the Profile for lordghost Click here to Send lordghost a Private Message Visit lordghost's homepage! Find more posts by lordghost Add lordghost to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
LOSTMAN
.novellino.

User info:
Registered: Feb 2009
Posts: 7 (0.00 al dì)
Location:
Corso:
Anno:
Time Online: 1:25:50 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ti ringrazio
ma purtroppo il fattoriale
e l unica che so fare perche e la piu scontata

21-02-2009 17:16
Click Here to See the Profile for LOSTMAN Click here to Send LOSTMAN a Private Message Find more posts by LOSTMAN Add LOSTMAN to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 02:31.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.208 seconds (68.54% PHP - 31.46% MySQL) con 26 query.