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 21: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 01: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 $v0, 4           # $v0 codice della print_string
  la $a0, msgn      # $a0 indirizzo della stringa
  syscall             # stampa della stringa

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

  bltz $v0, letturan
  move $s0, $v0

# Lettura di k
letturak:
  li $v0, 4           # $v0 codice della print_string
  la $a0, msgk      # $a0 indirizzo della stringa
  syscall             # stampa della stringa

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

  bltz $v0, letturak
  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 $v0, 4        # codice della print_int
    la $a0, msgr
    syscall

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


#uscire o continuare
  li $v0, 4           # $v0 codice della print_string
  la $a0, msgx      # $a0 indirizzo della stringa
  syscall             # stampa della stringa

  la $a0, chr          # $a0 indirizzo del buffer
  li $a1, 2
  li $v0, 8           # $v0 codice della read_int
  syscall             # legge l’intero n e lo carica in $v0

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

  bne $a0, 99, esci

    li $v0, 4        # codice della print_int
    la $a0, msgreb
    syscall   
    j letturan


# Termine del programma    
esci:
    li $v0, 4        # codice della print_int
    la $a0, msgend
    syscall

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




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

s:
  addi $sp, $sp,-24          # alloca stack
  sw   $ra, 20($sp)        # salvo return address
  sw   $a0, 16($sp)        # salvo l’argomento n
  sw   $a1, 12($sp)        # salvo l’argomento k
  sw   $t0, 8($sp)        # salvo s(n-1, k-1)
  sw   $t1, 4($sp)        # salvo s(n-1, k)
  sw   $t2, 0($sp)        # salvo 1

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

#casi 1-2

  bnez $a1, caso3    #k!=0
  bnez $a0, caso2    #n!=0
  #caso1
    li $v0, 1
    j end
  #caso2
  caso2:
    blez $a0, caso3
    li $v0, 0
    j end
  caso3:
    bge $a0, $a1, caso4
    #caso3
      li $v0, 0
      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 $a1, 12($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   $t2, 0($sp)        # ripristino t2
  lw   $t1, 4($sp)        # ripristino t1
  lw   $t0, 8($sp)        # ripristino t0
  lw   $a1, 12($sp)        # ripristino parametro1
  lw   $a0, 16($sp)        # ripristino parametro2
  lw   $ra, 20($sp)        # ripristino return address
  addi $sp, $sp, 24        # 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 10: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 18: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 10:27.    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.066 seconds (61.07% PHP - 38.93% MySQL) con 23 query.