Little Man Computer program that finds Minimum of an Array: Find Min Code BRA ST
ID: 3881709 • Letter: L
Question
Little Man Computer program that finds Minimum of an Array:
Find Min Code
BRA START
ARRAY0 DAT 5
DAT 4
DAT 3
DAT 7
DAT 5
DAT 2
DAT 1
DAT 7
START LDA ARRAY0
STA MIN LOOP
LDA LOADINST
ADD ARRAYINDEX
STA LOADNEXT
LDA ARRAYINDEX
ADD ONE
STA ARRAYINDEX
LOADNEXT DAT 0
SUB MIN
BRP KEEPMIN
ADD MIN
STA MIN
KEEPMIN LDA LENGTH
SUB ARRAYINDEX
BRZ DONE
BRA LOOP
DONE LDA MIN
OUT
HLT
Write a Java/C/Javascript program that will translate the Little Man Computer's instructions from input into machine code output. The instructions of Little Man Computer are listed above, please review it.
Your program needs to:
1. Declare an array of two dimensions, 10 rows and 2 columns. Fill the array, the first column would be instruction, the second column will be the machine op code.
2. Take input one line at a time.
3. For each line, read the first three characters.
4. Loop through the array comparing the three characters with the data on the first column
5. get the second column data once you find the match in the first column.
6. Output the matched data.
Explanation / Answer
import java.util.*;
public class Mach
{
public static void main(String args[])
{
String arr[][]=new String[10][2];
String st;
Scanner in=new Scanner(System.in);
int i,j=0;
for(i=0;i<3;i++)
{j=0;
System.out.println("Enter a string");
st=in.nextLine();
arr[i][j]=st.substring(0,3);
j++;
System.out.println("Enter a string in three words");
st=in.nextLine();
arr[i][j]=st;
}j=0;
for(i=0;i<3;i++)
{j=0;
if(arr[i][j].equals(arr[i][j+1]))
System.out.println(arr[i][j]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.