The assignment is to make a console that accepts commands, but I can’t even properly figure out comparing the string to parse the command.
.data
cmdline: .asciiz "> "
helpline: .asciiz "> Commands:n> help - displays available commandsn> echo - returns text inputted after commandn> exit - exits programn>n"
helpcomp: .asciiz "help"
echocomp: .asciiz "echo"
exitcomp: .asciiz "exit"
noRecog: .asciiz "> Command not recognizedn> Input 'help' for a list of commandsn>n"
tempText: .asciiz "echo foundn"
buffer: .space 21
buffersize: .word 20
.text
j cmdLoop
cmdLoop:
li $v0, 4
la $a0, cmdline
syscall
la $s2, buffer
move $t2, $s2
syscall
move $a0,$t2
la $a1, buffersize
li $v0, 8
syscall
j help
help:
la $s3, helpcomp
move $t2, $s3
compareHelp:
lb $t2,($s2) # get next char from str1
lb $t3,($s3) # get next char from str2
bne $t2,$t3,compareExit # are they different? if yes, fly
beq $t2,$zero,helpExecute # at EOS? yes, fly (strings equal)
addi $s2,$s2,1 # point to next char
addi $s3,$s3,1 # point to next char
j compareHelp
helpExecute:
li $v0, 4
la $a0, helpline
syscall
li $v0, 10
syscall
compareExit:
li $v0, 4
la $a0, tempText
syscall
li $v0, 10
syscall
Here’s the MIPS code I have right now, and here’s what I want it to do written in java
public class Console {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("> ");
while(true) {
String command = input.nextLine();
if(command.contains("help")) {
System.out.print("Commands:"
+ "nhelp - displays available commands"
+ "necho - prints the text inputted right after echo"
+ "nexit - quits out of the program"
+ "n> ");
} else if (command.contains("echo")) {
String echo = command.substring(5, command.length());
System.out.println(echo);
System.out.print("> ");
} else if (command.contains("exit")) {
break;
}
}
input.close();
}
}
I’ve tried (and failed) using stuff I’ve found online, but they’re built for both or neither of the strings to be inputted by the user.
2