Etant un peu fatigué ce soir, j'ai eut envie de faire quelque chose de nouveau et pas trop dur.
J'ai donc eut l'idée en regardant un bouquin d'ASM (pour x86) de tester l'assembleur pour MIPS.
Citation : Pas de titre
Les jeux d'instructions de base (en particulier MIPS I) sont si simples et efficaces qu'un bon nombre de cours d'architecture des ordinateurs, autant dans les universités que les écoles techniques, se portent sur l'étude de l'architecture MIPS.
Si j'en crois wikipedia, l'ASM pour MIPS est simple.
J'ai dont installé spim, un simulateur de R2000/R3000 et lu quelques trucs sur l'ASM pour MIPS(I).
A priori c'est simple d'utilisation, j'essaie donc le classique hello world (je met le code dans un fichier mips.asm et je tape load "mips.asm") et la...bah ca marche pas.
Si je j'utilise ce code (c'est bien asciiz) :
.text
main:
la $a0, hello_msg
li $v0, 4
syscall
li $v0,10
syscall
.data
hello_msg: .asciiz "Hello World\n"
...Rien ne se passe.
Bon, je cherche pas trois heures. Je prend un hello world sur google :
.data # Datensegment
str: .asciiz "Hello World!\n" # String ablegen(oui, il y a bien un z)
.text # Codesegment
main: li $v0, 4 # 4 = Print_string
la $a0, str # Adresse des Strings übergeben
syscall # Systemfunktion aufrufen
li $v0, 10 # 10 = Quit
syscall # Programm beenden
et la :
(spim) load "mips.asm"
spim: (parser) Label is defined for the second time on line 4 of file mips.asm
main: li $v0, 4 # 4 = Print_string
Bon ok. Je comprend pas trop pourquoi spim me dit ca :/
Je suis fatigué ce soir, je vais sur 99 bottles of beer :
####################################################
#Author: Dean Liu
#Contact: deanliu@cs.ucsb.edu
# deanliu@umail.ucsb.edu
#Date: May 1st,2005
#Description: MIPS Assembly version of
# 99 bottles
# of beer on the wall
####################################################
.data #data portion
strng: .asciiz " bottles of beer on the wall, "
strng2: .asciiz " bottles of beer "
strng3: .asciiz "\ntake one down and pass it around, "
strng4: .asciiz " bottle of beer on the wall "
strng5: .asciiz " bottle of beer "
strng6: .asciiz " bottles of beer on the wall.\n "
one: .word 1
.text #code section
main: #main
li $a2, 1 #
li $a3, 99 #start with 99
loop: jal PRNTB #prnt bottle count
la $a0, strng #print strng
li $v0, 4 #
syscall #
jal PRNTB #
la $a0, strng2 #print strng2
li $v0, 4 #
syscall #
la $a0, strng3 #print strng3
li $v0, 4 #
syscall #
sub $a3, $a3, 1 #subtract one
jal PRNTB #
la $a0, strng6 #print strng6
li $v0, 4 #
syscall #
bne $a3, $a2, skip #handles one
#bottle on wall
jal ONEBOT #
skip: bnez $a3, loop #Loop if not equal
#to 0
li $v0, 10 #exit
syscall #
####################################################
# Routine: PRINTB($a0)
# Description: Prints out current bottle count
####################################################
PRNTB: move $a0, $a3 #prnt bottle count
li $v0, 1 #
syscall #
jr $ra #return from method
####################################################
# Routine: ONEBOT($a0)
# Description: Handles one bottle count.
####################################################
ONEBOT: addi $sp,$sp,-4 #allocate
sw $ra,0($sp) #store rtrn
#address
jal PRNTB #
la $a0, strng4 #print strng4
li $v0, 4 #
syscall #
jal PRNTB #
la $a0, strng5 #print strng5
li $v0, 4 #
syscall #
la $a0, strng3 #print strng3
li $v0, 4 #
syscall #
sub $a3, $a3, 1 #subtract one
jal PRNTB #
la $a0, strng6 #print strng6
li $v0, 4 #
syscall #
lw $ra,0($sp) #load address
addi $sp,$sp,4 #pop
jr $ra #rtrn from method
(spim) load "mips.asm"
spim: (parser) Label is defined for the second time on line 19 of file mips.asm
main: #main
^
=>vous l'avez compris, à chaque fois que j'utilise le label main, je me fais insulter par spim.
Quelqu'un peut-il m'expliquer cela? (j'aimerais bien arriver à faire marcher un simple programme quand même )
je connais pas du tout ce que tu es en train d'utiliser, mais avec nasm, sous windows c'est "_main" et sous linux c'est "_start"
Nasm c'est un assembleur pour x86 (or ici je parle de MIPS)
Et de toute façon ca change rien :/
.data
hello: .asciiz "hello\n" # hello pointe vers "hello\n\0"
.text
.globl __start
__start:
li $v0, 4 # la primitive print_string
la $a0, hello # a0 l'adresse de hello
syscall
(spim) load "mips.spi"
spim: (parser) Label is defined for the second time on line 5 of file mips.spi
__start:
^
Par contre, j'ai trouvé un truc :
revan@azerty:~$ spim -notrap -file mips.spi
SPIM Version 7.3. of August 28, 2006
Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
All Rights Reserved.
See the file README for a full copyright notice.
hello
Attempt to execute non-instruction at 0x0040000c
revan@azerty:~$
Dommage que ca se finisse par une erreur.
.data
hello: .asciiz "hello\n" # hello pointe vers "hello\n\0"
.text
.globl main
main:
li $v0, 4 # la primitive print_string
la $a0, hello # a0 l'adresse de hello
syscall
revan@azerty:~$ spim -file mips.spi
SPIM Version 7.3. of August 28, 2006
Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu).
All Rights Reserved.
See the file README for a full copyright notice.
Loaded: /usr/lib/spim/exceptions.s
hello
Attempt to execute non-instruction at 0x00400030
revan@azerty:~$
Même probleme...
edit:
le programme de 99 bottles of beer se finit sans erreur par contre
Assembleur pour R2000 (MIPS I)
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Python c'est bon, mangez-en.