Δημοσιεύτηκε: 15 Μαρ 2012, 22:43
από Tasudo
Καλησπέρα,
φτιάχνω ένα πρόγραμμα σε Assembly(προσομοιωτής MARS)σε MIPS το οποιο θελω να κάνει τα εξής:

* Ζητάει από τον χρήστη έναν ακέραιο ώστε με αυτόν να δημιουργήσει έναν ΝxΝ πίνακα
* Ο χρήστης γεμίζει τις θέσεις του πίνακα με ακεραίους
* Ζητάει από τον χρήστη έναν ακέραιο
* Ο ακέραιος αυτός είναι οι διαστάσεις ενός πίνακα που αποτελεί υποπίνακα του ΝxΝ

Ο χρήστης θα πρέπει επιπλέον να εισάγει την απόσταση του πρώτου στοιχείου του υποπίνακα από το αριστερό, αλλά και από το άνω άκρο του
αρχικού πίνακα, ώστε να μπορεί να προσδιοριστεί η ακριβής θέση του υποπίνακα.Το πρόγραμμα θα αντιγράφει τον αρχικό πίνακα σε έναν νέο πίνακα, με τη διαφορά
ότι στη θέση του υποπίνακα θα τοποθετεί τον ανάστροφο του αρχικού υποπίνακα.
Τέλος, θα εκτυπώνεται ο τελικός πίνακας στην οθόνη.

-*************************************************************************************************************************************************************************************************************

Έχω κάνει την κύρια δομή του προγράμματος,αλλά με το reverse έχω κολλήσει 2 μέρες τώρα,έχει κανείς προτάσεις??
Κώδικας: Επιλογή όλων



.data

.align 2
main_array: . space 800


label_string_0:.asciiz"Please define the dimensions of the matirx: "
label_string_1:.asciiz"Now you have to fill the matrix! "
label_string_2:.asciiz"Please give an integer: "

label_string_3:.asciiz"Please define the dimensions of the submatrix: "
label_string_4:.asciiz"Please define the left distance: "
label_string_5:.asciiz"Please define the upper distance: "
label_string_6:.asciiz"FALSE USER INPUT! "
newLine:.asciiz"\n"


.text
.globl main

main:

la $a0,label_string_0 # Prints a message to the user to define the dimensions of the matrix
li $v0,4
syscall

li $v0,5 # User types the dimensions of the matrix(main_array)
syscall
add $t0,$v0,$0 # $t0 = Dimensions of the matrix

la $a0,label_string_1 # Prints a message to the user to fill the matrix
li $v0,4
syscall

la $a0,newLine # Changes line
li $v0,4
syscall

li $t9,0 # Register $t9 is used to point the adress of the cell at main_array
li $t1,0 # Register $t1 = i ,in order to create the for loop
li $t2,0 # Register $t2 = j ,in order to create the second for loop

for_1:
bge $t1,$t0,endfor_1 # if ( i < ArraySize)



for_2:
bge $t2,$t0,endfor_2 # if ( j < ArraySize)

la $a0,label_string_2 # Prints a message to the user to enter an integer to the matrix
li $v0,4
syscall

li $v0,5 # User types an integer
syscall
add $t3,$v0,$0

sw $t3,main_array($t9) # Saves the data of refister $t3
addi $t9,$t9,4 # Moves to the next "cell" of the matrix

addi $t2,$t2,1 # Continuation of the ForLoop2
j for_2

endfor_2:
addi $t1,$t1,1 # i ++ in order to run the for loop again
li $t2,0 # Register $t2 = 0 again in order to be able to run again the second for loop
j for_1 # Continuation of the ForLoop 1



endfor_1:


la $a0,label_string_3 # Prints a message to the user to enter the dimensions of the submatrix
li $v0,4
syscall

li $v0,5 # User enters the dimensions of the submatrix
syscall
add $t4,$v0,$0

bge $t0,$t4,L1 # Checks if the dimensions of the submatrix
# Fit with the dimensions of the "main" matrix
la $a0,label_string_6
li $v0,4
syscall

j end

L1:
la $a0,label_string_4 # Prints a message to the user to enter the left distance
li $v0,4
syscall

li $v0,5 # User enters an integer
syscall # NOTE: Left distance must be within limits
add $t5,$v0,$0

la $a0,label_string_5 # Prints a message to the user to enter upper distance
li $v0,4
syscall

li $v0,5 # User enters an integer
syscall # NOTE: Upper distance must be within limits
add $t6,$v0,$0


end:

li $v0,10 #Programm has finished running
syscall