I have a homework from the uni , we have to create a little program that does the following functions :
1)Create a new profile (name,surname,interests,visibilityFlag ecc)
2)Search a profile ( visibility of the searched profile must be true)
3)Erase your own profile
4)Show all 5 profiles (even those with vivibility false)
5)Exit (just finish the program)
So I already writed some code , I created 5 arrays for the profiles , but when i choose to create a profile , I start to create it from the profile1, and after that the prof instruction is to come back to the main menu and if I want to create another profile just do the same , but im not able to create the second profile , I just stay overwriting the data from the first one over and over again , I cannot find a way to pass to every single array until the fifth array.
Here's my code:
.data
## STRINGs MAIN MENU ##
welcome: .asciiz "\n\n\n********* WELCOME ***********\n\n\n\n"
objective: .asciiz "******************************************************\n\n the program task is to create max 5 profiles
and and being able to modify the data of your own
profile,erase your profile ,search for visibiles profiles
and output all the profiles even not visibles ones\n\n******************************************************"
choose: .asciiz "\n\n- what you wanna do?\n"
options: .asciiz "\n0)Create Profile\n1)Search Profile\n2)Erase Profilo\n3)Show all profiles\n4)Esci\n"
answer: .asciiz "\n\nAnswer:"
exitMsg: .asciiz "\n\nBYE BYE\n"
msgError: .asciiz "\n\n\nERROR, only numbers from 0-4n\n"
## STRING CREATE PROFILE##
Header: .asciiz "\n** CREATE PROFILE ** \n"
name: .asciiz "\n\n- Nome:"
surname: .asciiz "\n- Cognome:"
interests: .asciiz "\n\n- Interessi:\n"
userID: .asciiz "\n- UserID:"
password: .asciiz "\n- Password:"
email: .asciiz "\n\n- Email:"
visibility: .asciiz "\n- Visibilita:"
succes: .asciiz "\n\n****** PROFILE CREATED ******\n\n"
optionsProfile: .asciiz "\n\n0)Modify Profile 1)Go back to main menu\n\n"
## STRINGS SEARCH ##
nameSearch : .space 256
surnameSearch : .space 256
## STRINGS SHOW PROFILES ##
userID_mp: .asciiz "\nUserID:"
name_mp: .asciiz "\nName:"
surname_mp: .asciiz "\nSurname:"
interests_mp: .asciiz "\nInterests:"
newLine: .asciiz "\n"
profile1: .asciiz "\n\n\n\n** Profilo 1\n"
profile2: .asciiz "\n\n* Profilo 2\n"
profile3: .asciiz "\n\n* Profilo 3\n"
profile4: .asciiz "\n\n* Profilo 4\n"
profile5: .asciiz "\n\n* Profilo 5\n"
profile6: .asciiz "\n\n* Profilo 6\n"
profile7: .asciiz "\n\n* Profilo 7\n"
profile8: .asciiz "\n\n* Profilo 8\n"
profile9: .asciiz "\n\n* Profilo 9\n"
profile10: .asciiz "\n\n* Profilo 10\n"
newLine3: .asciiz "\n\n\n"
backToMainMenu: .asciiz "\n\n\n0)Back to main menu\n"
## PROFILES ##
Profile1: .word name1,surname1,interests1,userID1,visibility1,email1,password1
name1: .space 256
surname1: .space 256
interests1: .space 256
userID1: .space 256
visibility1: .space 256
email1: .space 256
password1: .space 256
Profile2: .word name2,surname2,interests2,userID2,visibility2,email2,password2
name2: .space 256
surname2: .space 256
interests2: .space 256
userID2: .space 256
visibility2: .space 256
email2: .space 256
password2: .space 256
Profile3: .word name3,surname3,interests3,userID3,visibility3,email3,password3
name3: .space 256
surname3: .space 256
interests3: .space 256
userID3: .space 256
visibility3: .space 256
email3: .space 256
password3: .space 256
Profile4: .word name4,surname4,interests4,userID4,visibility4,email4,password4
name4: .space 256
surname4: .space 256
interests4: .space 256
userID4: .space 256
visibility4: .space 256
email4: .space 256
password4: .space 256
Profile5: .word name5,surname5,interests5,userID5,visibility5,email5,password5
name5: .space 256
surname5: .space 256
interests5: .space 256
userID5: .space 256
visibility5: .space 256
email5: .space 256
password5: .space 256
.text
main:
Main_Menu:
## the main menu functions ##
li $v0,4
la $a0,welcome
syscall
li $v0,4
la $a0,objective
syscall
li $v0,4
la $a0,choose
syscall
li $v0,4
la $a0,options
syscall
li $v0,4
la $a0,answer
syscall
## READ INPUT AND SAVES IN $t0 ##
li $v0,5
syscall
move $t0,$v0 # salva la scelta in t0
## CHOOSE ONE FUNCTION##
## counter?
li $s0,1
li $t1, 0
beq $t0, $t1, Create_Profile # Create a Profile starting from 1 ending 5
li $t1, 1
beq $t0, $t1, Search_Profile # Search a Public profile
li $t1, 2
beq $t0, $t1, Erase_Profile # Erase your profile
li $t1, 3
beq $t0, $t1, Show_Profiles # Show all profiles
li $t1, 4
beq $t0, $t1, Exit # Just finish
la $a0, msgError
li $v0,4
syscall
j Main_Menu
## FUNCTIONS ##
Create_Profile:
## start from 1 , come back to main_menu and create the second , come back again and the third...
li $s5,1
li $t0,1
beq $s5,$t1,createProfile1
li $t1,2
beq $s5,$t1,createProfile2
## and the rest
createProfile1:
li $t0,1
addi $s5, $s5, 4
li $v0,4
la $a0,name
syscall
la $a0, name1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,surname
syscall
la $a0, surname1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,interests
syscall
la $a0, interests1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,userID
syscall
la $a0, userID1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,password
syscall
la $a0, password1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,email
syscall
la $a0, email1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,visibility
syscall
la $a0, visibility1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0, succes
syscall
j options_Profile
createProfile2:
li $t0,2
li $v0,4
la $a0,nome
syscall
la $a0, nome2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,cognome
syscall
la $a0, cognome2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,interessi
syscall
la $a0, interessi2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,userID
syscall
la $a0, userID2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,password
syscall
la $a0, password2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,email
syscall
la $a0, email2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,visibilita
syscall
la $a0, visibilita2
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0, succes
syscall
j options_Profile
createProfile3:
createProfile4:
createProfile5:
createProfile6:
createProfile7:
createProfile8:
createProfile9:
createProfile10:
options_Profile:
## show some options
li $v0,4
la $a0, optionsProfile
syscall
li $v0,4
la $a0,answer
syscall
## read an Integer
li $v0,5
syscall
move $t0,$v0
li $s1,1
beq $t0,$s1,Main_Menu
li $s1,0
beq $t0,$s1,Modify_Profile
Modify_Profile:
li $t1,1
beq $t0,$t1,Mod_Profile1
li $t1,2
beq $t0,$t1,Mod_Profile1
Mod_Profile1:
## Just do the same like when you create a profile
li $t0,1
addi $s5, $s5, 4
li $v0,4
la $a0,name
syscall
la $a0, name1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,surname
syscall
la $a0, surname1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,interests
syscall
la $a0, interests1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,userID
syscall
la $a0, userID1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,password
syscall
la $a0, password1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,email
syscall
la $a0, email1
li $a1, 256
li $v0, 8
syscall
li $v0,4
la $a0,visibility
syscall
la $a0, visibility1
li $a1, 256
li $v0, 8
syscall
la $a0, backToMainMenu ## opzion torna al menu p...
li $s0,4
syscall
li $v0,5
syscall
move $t0,$v0
li $s1,0
beq $t0,$s1,Main_Menu
Search_Profile:
la $a0, nome
li $v0,4
syscall
la $a0, nomeCerca
li $a1, 256
li $v0, 8
syscall
la $a0, cognome
li $v0,4
syscall
la $a0, cognomeCerca
li $a1, 256
li $v0, 8
syscall
Erase_Profile:
Show_Profiles:
li $t0,1
beq $t0,1,Show_Profile1
addi $t0, $t0, 4
beq $t0,2,Show_Profile2
addi $t0, $t0, 4
beq $t0,3,Show_Profile3
addi $t0, $t0, 4
beq $t0,4,Show_Profile4
addi $t0, $t0, 4
beq $t0,5,Show_Profile5
addi $t0, $t0, 4
beq $t0,11,go_MainMenu
Show_Profile1:
la $a0, profile1
li $v0,4
syscall
la $s0, Profile1
la $a0,userID_mp
li $v0,4
syscall
lw $t1,12($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,name_mp
li $v0,4
syscall
lw $t1,0($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,surname_mp
li $v0,4
syscall
lw $t1,4($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,interests_mp
li $v0,4
syscall
lw $t1,8($s0)
la $a0,0($t1)
li $v0,4
syscall
Show_Profile2:
la $a0, profile2
li $v0,4
syscall
la $s0, Profile2
la $a0,userID_mp
li $v0,4
syscall
lw $t1,12($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,name_mp
li $v0,4
syscall
lw $t1,0($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,surname_mp
li $v0,4
syscall
lw $t1,4($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,interests_mp
li $v0,4
syscall
lw $t1,8($s0)
la $a0,0($t1)
li $v0,4
syscall
Show_Profile3:
la $a0, profile3
li $v0,4
syscall
la $s0, Profile3
la $a0,userID_mp
li $v0,4
syscall
lw $t1,12($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,name_mp
li $v0,4
syscall
lw $t1,0($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,surname_mp
li $v0,4
syscall
lw $t1,4($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,interests_mp
li $v0,4
syscall
lw $t1,8($s0)
la $a0,0($t1)
li $v0,4
syscall
Show_Profile4:
la $a0, profile4 ## number
li $v0,4
syscall
la $s0, Profile4 ## adress
la $a0,userID_mp
li $v0,4
syscall
lw $t1,12($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,name_mp ## name
li $v0,4
syscall
lw $t1,0($s0) ## adress
la $a0,0($t1)
li $v0,4
syscall
la $a0,surname_mp ## surname
li $v0,4
syscall
lw $t1,4($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,interests_mp ## interests
li $v0,4
syscall
lw $t1,8($s0)
la $a0,0($t1)
li $v0,4
syscall
Show_Profile5:
la $a0, profile5 ## number profile
li $v0,4
syscall
la $s0, Profile5 ## adress
la $a0,userID_mp
li $v0,4
syscall
lw $t1,12($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,name_mp ## nome
li $v0,4
syscall
lw $t1,0($s0) ## direccion de nome1
la $a0,0($t1) ## stampa nome1
li $v0,4
syscall
la $a0,surname_mp ## cognome
li $v0,4
syscall
lw $t1,4($s0)
la $a0,0($t1)
li $v0,4
syscall
la $a0,interests_mp ## interessi
li $v0,4
syscall
lw $t1,8($s0)
la $a0,0($t1)
li $v0,4
syscall
go_MainMenu:
la$a0,backToMainMenu
li $s0,4
syscall
li $v0,5
syscall
move $t0,$v0
li $s1,0
beq $t0,$s1,Main_Menu
Exit:
la $a0, exitMsg
li $v0, 4
syscall
li $v0,10 # exit
syscall
and Im running my program in the SPIM emulator.
sorry for my bad english