简体   繁体   English

MIPS为什么我无法打印所选的阵列位置?

[英]MIPS Why I can't print the selected array position?

Whit this code the simulator says: memory addres out of bound" and print(null) t0 is the index, initially set to 0, it's portion of a cicle. 模拟器说这句话的代码是:“内存地址超出范围”,print(null)t0是索引,最初设置为0,它是cicle的一部分。

        la $t1, nome #array address
        mul $t2, $t0, 4 # t2=index*4
        add $t3, $t2, $t1 

        lw $a0, nome($t2)
        li $v0, 4
        syscall

That's the write: 就是这样写:

        la $t1, nome 
        mul $t2, $s2, 4 #s2 index

        la $v0, 4 
        la $a0, nomedom #input string
        syscall 
        li $v0, 8 
        syscall
        sw $v0, nome($t2)

Here the proto of the program, i just leaved one array for reducing lenght Now, if you run this code you can run just creation and list, but if you run list after create a profile, function list will not listing nothing, but i guess I read the same memory location.. after that, if you run another time creation it will print on screen the precedent data!! 这是程序的原型,我只留下了一个数组来减少长度现在,如果您运行此代码,则可以只运行创建和列表,但是如果在创建配置文件后运行list,函数列表将不列出任何内容,但是我想我读取了相同的内存位置。.在此之后,如果您运行其他时间创建,它将在屏幕上打印先行数据! And i don't understeand why! 而且我不明白为什么! I don't print anything more than the question for the input 除了输入的问题,我只打印其他内容

.data #variabili


nome: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
cognome: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
interessi: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
userid: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
email: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
password: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
pp: .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
cont: .word 0 #METTERE STO CONTATORE COME RIFERIMENTO INDIRIZZO NEGLI INDICI DEGLI ARRAY


selezione: .byte 0

#menu
menu: .asciiz "\n\n\n\n\n\n1)Creation profile\n2)Modificare il proprio  profilo\n3)Cancellare \n4)LIST\n5)Cercare un profilo pubblico per nome e cognome\n0)USCITA\n\n\nSelezione: "
nomedom: .asciiz "Inserire nome: "
cognomedom: .asciiz "Inserire cognome: "
useriddom: .asciiz "Inserire UserID: "
interessidom: .asciiz "Inserire interessi: "
emaildom: .asciiz "Inserire E-mail valida: "
passdom: .asciiz "Inserire password: "
ppdom: .asciiz "Profilo pubblico(0) o privato(1): "
menurid: .asciiz "\n\n\nModifica Profilo(1)\nMenu principale(0)  :"
uscita: .asciiz "SEI USCITO"
intro: .asciiz "             --------"
troppitx: .asciiz "\n\nIL NUMERO MASSIMO DI PROFILI È 10"
.text


main:
li $s2, 0
li $v0, 4 
la $a0, intro 
syscall

menupri: 
#-------------------------------------------------------------------<<<<<<<MENU
    li $v0, 4 # 4 è il codice di print_string
la $a0, menu # domanda all'utente
syscall
li $v0, 5 #leggo intero
syscall
move $t6,$v0 #memorizzo l'intero in t6

li $t1, 1
li $t2, 2
li $t3, 3
li $t4, 4
li $t5, 5
li $t0, 0
beq $t1, $t6, FUNZIONE_CREATION 
beq $t2, $t6, FUNZIONE_MODIFICA
beq $t3, $t6, FUNZIONE_CANCELLAZIONE
beq $t4, $t6, FUNZIONE_LIST
beq $t5, $t6, FUNZIONE_RICERCA
beq $t0, $t6, USCITA



#----------------------------------------------------------------------------<<<<FUNCTION


.ent FUNZIONE_CREATION
FUNZIONE_CREATION:






bgeu $s2, 10, TROPPI #s2 indice e contatore




li $t1, 0
li $t2, 0
li $t3, 0
        la $t1, nome #indirizzo dell'array
        mul $t2, $s2, 4 #di quanto devo spostarmi t2=indice*4
        add $t3, $t2, $t1 #indirizzo array di indice s2 è in t3  



la $v0, 4 #nomedom
la $a0, nomedom
syscall #scrivo richiesta
li $v0, 8 # lettura
syscall
sw $v0, nome($t2)


add $s7, $s7, 1

li $v0, 4 # 4 è il codice di print_string
la $a0, menurid # domanda all'utente
syscall
li $v0, 5 #leggo intero
syscall
move $t2,$v0 #memorizzo l'intero in t2
li $t1, 1
li $t0, 0
beq $t1, $t2, FUNZIONE_MODIFICA #VA PASSATO L'INDICE COME ARGOMENTO
beq $t0, $t2, esci
esci:
#niente

.end FUNZIONE_CREATION
j menupri  #torna al menu principale


.ent FUNZIONE_LIST
FUNZIONE_LIST:

#VISUALIZZA I PROFILI PUBBLICI, se pp= pubblico di un indice scrive
li $t0, 0#indice e contatore
li $t7, 0
li $t1, 0
li $t2, 0
li $t3, 0
li $t5, 0
loop:
bgt $t0, 9, esci1


        la $t1, nome #indirizzo dell'array
        mul $t2, $t0, 4 #di quanto devo spostarmi t2=indice*4
        add $t3, $t2, $t1 #indirizzo array di indice t0 è in t3  


#lw $t7, pp
beq $t7, $zero, scrittura #t7 è pp
scrittura:

        li $v0, 4
        la $a0, nome($t2)

        syscall


addi $t0, $t0,1 #condizione e campi del ciclo #prima era sotto bgt
j loop
esci1:
#niente

.end FUNZIONE_LIST
j menupri  #torna al menu principale

.ent FUNZIONE_RICERCA
FUNZIONE_RICERCA:
.end FUNZIONE_RICERCA
j menupri  #torna al menu principale

.ent FUNZIONE_MODIFICA
FUNZIONE_MODIFICA:



.end FUNZIONE_MODIFICA
j menupri  #torna al menu principale

.ent FUNZIONE_CANCELLAZIONE
FUNZIONE_CANCELLAZIONE:
.end FUNZIONE_CANCELLAZIONE
j menupri  #torna al menu principale


.ent USCITAMEN
USCITAMEN:
j menupri
.end USCITAMEN


.ent TROPPI
TROPPI:
li $v0, 4 
la $a0, troppitx
syscall
    j menupri
.end USCITAMEN



#fine
USCITA: 
li $v0, 4 # uscita
la $a0, uscita
syscall
li $v0,10
syscall

I am guessing that you want nome to be an array of integers. 我猜您希望nome是整数数组。 In that case, you should be having $v0 = 1 instead of $v0 = 4 . 在这种情况下,您应该拥有$v0 = 1而不是$v0 = 4 4 in $v0 prints a string. $v0 4打印一个字符串。 Since nome has 0 at each location, the value of 4 in $v0 prints 0 as an ASCII. 由于nome具有0在每个位置,值4$v0打印0为ASCII。 And 0 is the ASCII value of NULL . 0NULL的ASCII值。 This explains your undesired output. 这解释了您不希望的输出。

If you want to print 0 as an integer, you need $v0=1 . 如果要将0打印为整数,则需要$v0=1

Change this: 更改此:

lw $a0, nome($t2)
li $v0, 4
syscall

to this: 对此:

lw $a0, 0($t3)    # Since you have $t3 = $t2 + $t1
li $v0, 1         # It is same as Address of nome[0] + index*4
syscall           # which is same as Address of nome[i]; i being $t2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM