MIPS for aber wie



  • Hallo wie mache ich eine simple for schleife

    for1:		addu	$t4, $t4, 1			#i++
    		bge	$t4,0x3,  rof1
    		addu	$t0, $t0, $t2			#$t0 := $t0 + $t2 <=> $t0 := $t0 + vb
    		j for1					#END
    rof1:							#exit loop
    

    Mein problemm ist aber folgendes ich will den befehl
    addu $t4, $t4, 1 am ende der for schleife haben und zwar vor j for1 aber dann funktionier die schleife nicht richtig kann ir einer weiterhelfen????



  • Fügt dein Assembler automatisch ein nop hinter dem jump ein?



  • Ich habe delayed Brances und delayed load und pseudo befehle und Mapped IO deaktivierd hilft dir das was?



  • Initialisierst Du $t4 vor der Schleife?

    Soll der Schleifenkörper mindestens einmal ausgeführt werden? (Das wäre dann eine do-while-schleife)



  • Klar kleich mit 0. Ich will so etwas in der art wie das hier funk aber nicht

    bgt $t4,0x3,rof1
    for1:		add	$t0, $t0, $t2			#$t0 := $t0 + $t2 <=> $t0 := $t0 + vb
    		addi	$t4, $t4, 1			#i++
    		blt	$t4,0x3,  for1
    rof1:
    

    Oder so enlich!! 😞



  • Probier mal das hier:

    for1:		bgt $t4, 3, rof1
    		add	$t0, $t0, $t2		#$t0 := $t0 + $t2 <=> $t0 := $t0 + vb
    		addi	$t4, $t4, 1			#i++
                j forl
    rof1:
    

    Was meinst Du denn damit, dass es nicht funktioniert?

    Und paste mal bitte noch etwas Code um die Schleife herum.



  • Nai gehta uch nicht die for schleife wird 4 mal durchgelaufen

    der code ist

    .data
    va:	.word 0x0
    vb:	.word 0x1
    vc:	.word 0x4
    
    #############################################################################################################################
    ##															   ##
    ##					Arxh dikth gia Text apo8hkeush							   ##
    ##															   ##
    #############################################################################################################################
    
    	.text
    
    #############################################################################################################################
    #															    #
    #						Telos dhlosh Metablhton							    #
    #															    #
    #############################################################################################################################
    
    #############################################################################################################################
    ##															   ##
    ##						Arxh kurias sunarthshs							   ##
    ##															   ##
    #############################################################################################################################
    
    	.globl main
    main:
    
    	#Arxh metaforas dedomenon apo thn periferiakh mnhmh stous kataxorites
    	###########################
    
    	#Apo8hkeushs mias 32bit lekseis h vb ston kataxorith $t0
    	###########################
    
    		la 	$t2, vb				#$t2 = MEM[vb]
    		lw 	$t0, 0($t2)			#$t0 = &($t2) dhladh $t0 = vb
    		lw 	$t2, 0($t2)			#$t2 = &($t2) dhladh $t0 = $t2 = vb
    	#h vb briskete tora sto $t0 kai mia antigrafh ths vb sto $t2 to opio
    	#8a mas boh8ish sths praksis
    	#
    	#
    	#
    
    	#Apo8hkeushs mias 32bit lekseis h vb ston kataxorith $t2
    	###########################
    
    		la	$t3, vc				#$t3 = MEM[vb]
    		lw	$t1, 0($t3)			#$t1 = &($t3) dhladh $t0 = vb
    		lw	$t3, 0($t3)			#$t3 = &($t3) dhladh $t0 = $t3 = vc
    	#h vc briskete tora sto $t0 kai mia antigrafh ths vb sto $t2 to opio
    	#8a mas boh8ish sths praksis
    	#
    	#
    	#
    
    	#Arxh ulopoihseis kurio programmatos
    	###########################
    
    	#edo ftiaxno enan metyrith (Counter) pou 8a xriasth gia thn for
    		li 	$t4, 0				#i := 0
    
    	#Edo hlopoioo mia epnalalipthkh diadikasia gia 3*vb
    	############ ###############
    for1:		addu	$t4, $t4, 1			#i++
    		bge	$t4,0x3,  rof1
    		addu	$t0, $t0, $t2			#$t0 := $t0 + $t2 <=> $t0 := $t0 + vb
    		j for1					#END
    rof1:							#exit loop
    
    	#Mhdenizo pali ton metrith mou
    		li 	$t4, 0				#i := 0
    
    	#edo hlopoio mia epanaliptikh diadika gia ton upologismou tou 5*vb
    	############################
    for2:		addu	$t4, $t4, 1			#i++
    		bge	$t4, 0x5, rof2
    		addu	$t1, $t1, $t3			#$t1 := $t1 + $t1
    		j for2					#END for2
    rof2:
    
    	#edo ulopoio thn telikh pros8esh ton duo metablhton
    	############################
    
    		addu	$s0, $t0, $t1			#$s0 := $t1 + $t2
    
    	#Tora apo8hkeuo thn telikh timh
    	############################
    		sw	$s0, va				#Apo8hkeush tou kataxorith $s0 ekei pou dixnh o va. MEM[va] = $t0
    
    	#Bye bye
    	##########################
    		li $v0,10
    		syscall
    

    und ich will die for schleife verender aber wie?



  • Normaler weise muste es mit diesen code funktionieren in ein anderen programm das ich geschrieben habe funk das

    for1:		bge $t4, 3, rof1 
    		add    $t0, $t0, $t2        #$t0 := $t0 + $t2 <=> $t0 := $t0 + vb 
            	addi    $t4, $t4, 1            #i++ 
    		j for1 
    rof1:
    


  • das programm macht folgendes vb = 3*vb + 5*vc aber ohne multiplikation befehle!



  • Man man ich habe den vehler gefunden neine logik ist erste klase weist du wo der fehler was ich hate icm speicher schon daten aber sie musten o sein oh man. Danke jeden fahls!!! Hast mir geholfen!>



  • ok 🙂


Anmelden zum Antworten