Μπορεί κάποιος να με πει αν έκανα πλήρης μετάφραση σε assembly
όπως θα την έκανε ένα μηχάνημα, πχ ένας compiler; Ξέχασα τίποτα;
C:
Κώδικας:int *append(int length, int *head) { /*The list is actually an array and the head is a pointer that start's with the address arrayAddress - 2. So: head + 2 is the start address of the array (this is true until the head change's). */ //Print message. printf("Give value to append: "); //Read the input. int value; scanf("%d", &value) //Increase the head to make space for two integers. head = head + 2 //(head + 2 * 4 bytes) //Increase the length of the list. length = length + 1 //Store the integers. *head = value #Array[i] = value *(head + 1) = length #Array[i+1] = length //Return head. return head }
Assembly:
Κώδικας:#=============================Append item into a static list=============================# append: #----------------------------Prologue----------------------------# addi $sp $sp -8 #Allocate memory. sw $a0 4($sp) #Last item Address. This is the head variable. sw $a1 0($sp) #List Length. This is the length variable. #----------------------------Prologue----------------------------# #-------------------------------------------Body-------------------------------------------# #Print: "Give value to append: " li $v0 4 la $a0 gta syscall #------------Read the input------------# li $v0 5 syscall addi $sp $sp -4 #Allocate 4 more bytes. sw $v0 0($sp) #Save the input value. This is the value variable. #------------Read the input------------# #Read data from memory. lw $t1 8($sp) #Get the last address lw $t2 4($sp) #Get the length. lw $t3 0($sp) #Get the input. #Make calculations. addi $t1 $t1 8 #Increase the last address. addi $t2 $t2 1 #Increase the length. #Append value and id on the list. sw $t3 0($t1) #Store the value. sw $t2 4($t1) #Store the id. #Save data on the memory. sw $t1 8($sp) #Save last address. sw $t2 4($sp) #Save length. #Return the last address of the list. lw $v0 8($sp) #-------------------------------------------Body-------------------------------------------# #----------------------------Epilogue----------------------------# #Free memory and return. addi $sp $sp 12 #----------------------------Epilogue----------------------------# jr $ra #=============================Append item into a static list=============================#
Εμφάνιση 1-4 από 4
-
15-11-16, 15:25 Μετάφραση C σε assembly mips "μηχανικά". #1
-
16-11-16, 03:09 Απάντηση: Μετάφραση C σε assembly mips "μηχανικά". #2
Απ΄ όσα θυμάμαι, μιας και δεν έχω ασχοληθεί πάρα πολύ είναι οκ.
ουδέν μονιμότερο του προσωρινού
-
17-11-16, 18:14 Απάντηση: Μετάφραση C σε assembly mips "μηχανικά". #3
Μηπως μπορει καποιος να μου μεταφρασει τον παρακατω αλγοριθμο σε γλωσσα assembly καθως δεν μου ολοκληρωνεται το compilation με επιτυχια!!
do {
Εμφανισε μηνυμα "Αριθμόσ: ";
Διαβασε αριθμόσ1;
αποτελεσμα= αριθμόσ1;
do {
Εμφανισε μηνυμα "Τελεστης: ";
Διαβασε τελεστη;
if (τελεστης δεν ειναι ‘+’, ‘-’, ‘*’, ‘/’, ‘%’, ‘=’) {
Εμφανισε μηνυμα λαθους ;
Βγεσ από το πρόγραμμα;
}
ΕΥΧΑΡΙΣΤΩ εκ των προτερων
-
19-11-16, 14:36 Απάντηση: Μετάφραση C σε assembly mips "μηχανικά". #4Κώδικας:
.data msg1: .asciiz "Αριθμός: " msg2: .asciiz "Τελεστης: " .text .globl main main: #Print a message. li $v0 4 la $a0 msg1 syscall #Read an integer and store it on $t0. li $v0 5 syscall move $t0 $v0 #Print a message. li $v0 4 la $a0 msg2 syscall #Read an integer and store it on $t1. # 0 = + # 1 = - # 3 = * # 4 = / # 5 = % # 6 = = li $v0 5 syscall move $t1 $v0 bne $t1 0 exit_program bne $t1 1 exit_program bne $t1 2 exit_program bne $t1 3 exit_program bne $t1 4 exit_program bne $t1 5 exit_program bne $t1 6 exit_program exit_program: li $v0 10 syscall
Παρόμοια Θέματα
-
"MSc" με μικρό "s" σε επαγγελματική κάρτα
Από researcher στο φόρουμ Εκτός θέματοςΜηνύματα: 20Τελευταίο Μήνυμα: 12-06-16, 19:05 -
Youtube: Subscriptions δεν πηγαίνουν σε προβολή "Λίστας".
Από vothros στο φόρουμ Software γενικάΜηνύματα: 1Τελευταίο Μήνυμα: 01-06-16, 20:50 -
Πρόσβαση "roaming" σε υπηρεσίες τύπου Netflix το 2017 στην Ευρωπαϊκή Ένωση
Από nnn στο φόρουμ ΕιδήσειςΜηνύματα: 10Τελευταίο Μήνυμα: 23-05-16, 19:48 -
Assembly(mips) Keyboard Interruption!!!
Από babaliaris στο φόρουμ Προγραμματισμός και γλώσσες προγραμματισμούΜηνύματα: 0Τελευταίο Μήνυμα: 13-12-15, 16:39
Bookmarks