[algo] ou autre langage ? c"est quoi ce truc
max
-
max -
max -
Salut à tous, j'ai ce code, il me semble que c'est de l'assembleur mais je n'arrive pas à le déchiffrer, y'a t il des pros pour m'orienter sur ce truc ?
meric d'avance
###############
## Data Segment
###############
.data
STR1: .asciiz "Please enter a number (0 to stop): "
STR2: .asciiz "Result is "
NL: .asciiz ".\n"
###############
## Text Segment
###############
.text
.globl main
#-----------------------------------------------------------
# Main Start
#-----------------------------------------------------------
main: addi $s0, $zero, 0 # $s0 = 0
addi $s1, $zero, 0 # $s1 = 0
addi $s2, $zero, 0 # $s0 = 0
loop: li $v0, 4 # system call for print_str
la $a0, STR1 # address of string to print
syscall # print the string
li $v0, 5 # system call for read_int
syscall # read the integer
## Check if $v0 == 0, if true goto exit
beq $v0, $zero, exit
## Result from read_int is stored in $v0
add $s0, $s0, $v0 #
blez $v0, loop1
add $s2, $s2, $v0 #
j loop # goto loop
loop1: add $s1, $s1, $v0 #
j loop
exit: li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s0, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s1, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s2, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
jr $ra # exit program
# Main End
#-----------------------------------------------------------
meric d'avance
###############
## Data Segment
###############
.data
STR1: .asciiz "Please enter a number (0 to stop): "
STR2: .asciiz "Result is "
NL: .asciiz ".\n"
###############
## Text Segment
###############
.text
.globl main
#-----------------------------------------------------------
# Main Start
#-----------------------------------------------------------
main: addi $s0, $zero, 0 # $s0 = 0
addi $s1, $zero, 0 # $s1 = 0
addi $s2, $zero, 0 # $s0 = 0
loop: li $v0, 4 # system call for print_str
la $a0, STR1 # address of string to print
syscall # print the string
li $v0, 5 # system call for read_int
syscall # read the integer
## Check if $v0 == 0, if true goto exit
beq $v0, $zero, exit
## Result from read_int is stored in $v0
add $s0, $s0, $v0 #
blez $v0, loop1
add $s2, $s2, $v0 #
j loop # goto loop
loop1: add $s1, $s1, $v0 #
j loop
exit: li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s0, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s1, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_str
la $a0, STR2 # address of string to print
syscall # print the string
li $v0, 1 # system call code for print_int
add $a0, $s2, $zero # integer to print,
syscall # print the integer
li $v0, 4 # system call code for print_str
la $a0, NL # address of string to print
syscall # print the string
jr $ra # exit program
# Main End
#-----------------------------------------------------------
9 réponses
-
Effectivement, c'est de l'assembleur, mais pas de l'Intel 80x86 en tous cas.
-
D'après Google, c'est de l'assembleur MIPS
https://homes.cs.washington.edu/~zahorjan/homepage/Tools/Cebollita/docs/asm-spec.shtml
http://www.cs.uwm.edu/~cs215/examples.html
https://en.wikipedia.org/wiki/MIPS_architecture -
wow deja 2 réponses
merci pour votre aide, est il possible d'intépréter ce code avec un utilitaire ?
;) -
Il faudrait un processeur MIPS pour faire tourner ce code...
à moins de trouver un émulateur, mais j'ignore s'il existe des émulateurs MIPS. -
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
salut
j'ai bien un simulateur MIPS
je l'ai fais touner dessus , en fait ca me demande d'ecrire plusieurs chiffres et au bout d'un moment ca me donne l'addiction de ces chiffres mais le probleme c'est qu'il y a des conditions que je n'arrive pas a trouver genre si le chiffres est sup à telle valeur alors donner le resultat
En décortiquant le truc je trouve pas ! -
ah là je ne pourrais pas t'aider, je ne connais rien à l'assembleur MIPS.
-
-
Ben a priori c'est là :
beq $v0, $zero, exit
Quand $v0 est = 0, on va sur exit où on affiche les résultats...
En plus, c'est marqué au début :
STR1: .asciiz "Please enter a number (0 to stop): "
-
En fait, si tu on rentre que des positifs, le registre qui reçoit les négatifs est vide, donc, en cas de sortie de boucle, le résultat de ce registre devrait être indéfini (ensemble vide) et non pas 0...
Idem si on ne saisit que des négatifs, le registre qui reçoit les positifs devrait être indéfini. Idem si l'utilisateur rentre tout de suite 0, aucun registre n'est incrémenté
c'est un peu d'aide, mais sur le fond je n'oublie rien ?
merci de vos reponse ;)