Kirk Scott Computer Science The University of Alaska Anchorage

65
The Minimal Instruction Set Computer (MISC) in Java: Demonstration of Graphical User Interface Programming Concepts Kirk Scott Computer Science The University of Alaska Anchorage 1

description

The Minimal Instruction Set Computer (MISC) in Java: Demonstration of Graphical User Interface Programming Concepts. Kirk Scott Computer Science The University of Alaska Anchorage. Overall Plan of Overheads. 1. An explanation of MISC in general - PowerPoint PPT Presentation

Transcript of Kirk Scott Computer Science The University of Alaska Anchorage

Page 1: Kirk Scott Computer Science The University of Alaska Anchorage

1

The Minimal Instruction Set Computer (MISC) in Java:

Demonstration of Graphical User InterfaceProgramming Concepts

Kirk ScottComputer Science

The University of Alaska Anchorage

Page 2: Kirk Scott Computer Science The University of Alaska Anchorage

2

1. An explanation of MISC in general 2. Graphical user interface modifications 3. Conclusion

Overall Plan of Overheads

Page 3: Kirk Scott Computer Science The University of Alaska Anchorage

3

1. An explanation of MISC in general

Page 4: Kirk Scott Computer Science The University of Alaska Anchorage

4

MISC is a Java simulation of a simple CPU The simulation includes a simple machine

language Machine programs can be written in this

language

An Introduction to MISC

Page 5: Kirk Scott Computer Science The University of Alaska Anchorage

5

MISC contains a simple operating system The operating system functions are

written in Java as part of the simulation In MISC, absolute machine code is loaded

at memory address 0 and executed there Program loading and execution in MISC

can be modified in several ways

Page 6: Kirk Scott Computer Science The University of Alaska Anchorage

6

Bytes and registers Bytes, words, and memory General remarks on machine instruction

execution Fetch, decode, and execute The machine language instruction set

The Basic Structure of MISC

Page 7: Kirk Scott Computer Science The University of Alaska Anchorage

7

General remarks on the form of machine language

An example program The Java methods comprising the simulation The command line interface A summary of the structure of the Java

simulation by class, constructor, and method

The Basic Structure, Continued

Page 8: Kirk Scott Computer Science The University of Alaska Anchorage

8

The MISC architecture makes use of 4 byte words

The contents of a register are modeled by an object containing a character array of 8 bytes

Bytes and Registers

Page 9: Kirk Scott Computer Science The University of Alaska Anchorage

9

Each bit is modeled by the presence of the character ‘1’ or the character ‘0’ in a position in an 8 byte array

The registers are packaged together in an array named “reg”

The index of the array identifies the particular register

Page 10: Kirk Scott Computer Science The University of Alaska Anchorage

10

Registers:

register name decimal index binary code identification in reg array of index   unused reg[0] "00000000"   general purpose   A reg[1] "00000001" B reg[2] "00000010" C reg[3] "00000011" D reg[4] "00000100"  

Page 11: Kirk Scott Computer Science The University of Alaska Anchorage

11

Registers, cont’d.:

register name decimal index binary code identification in reg array of index

memory offsets   codeoffsetreg[5] "00000101" dataoffset reg[6] "00000110" unused1 reg[7] "00000111" unused2 reg[8] "00001000" unused3 reg[9] "00001001"   flag reg[10] "00001010"  

Page 12: Kirk Scott Computer Science The University of Alaska Anchorage

12

Registers, cont’d.:

register name decimal index binary code identification in reg array of index

control unit registers   instruction reg[11] "00001011" operand1 reg[12] "00001100" operand2 reg[13] "00001101" extrareg[14] "00001110"

ALU registers   aluinreg1 reg[15] "00001111" aluinreg2 reg[16] "00010000" aluoutreg reg[17] "00010001"

Page 13: Kirk Scott Computer Science The University of Alaska Anchorage

13

A word in MISC consists of 4 bytes Memory is implemented as an array of

words The index of the array is the word offset into

memory   Memory: array name memory[]

Bytes, Words, and Memory

Page 14: Kirk Scott Computer Science The University of Alaska Anchorage

14

These are the general rules for move and arithmetic instructions◦ A register or a memory variable can be a

destination◦ A constant, a register, or a memory variable can

be a source◦ Memory to memory operations are not allowed

General Remarks on Machine Instruction Execution

Page 15: Kirk Scott Computer Science The University of Alaska Anchorage

15

A program is loaded to memory location 0 by default

The machine takes control of execution The machine steps through the program

code until it encounters an empty (“00000000”) instruction byte

Fetch, Decode, and Execute

Page 16: Kirk Scott Computer Science The University of Alaska Anchorage

16

Execution starts with the value 0 in the code offset register

The next 4 contiguous bytes of code memory are put into the instruction, operand1, operand2, and extra registers

After the retrieval of each instruction the code offset is incremented for the next retrieval

Page 17: Kirk Scott Computer Science The University of Alaska Anchorage

17

The MOVE Instruction assembly instruction method in simulation machine instruction MOVE register, register void moveDestRegSrcReg() “10000001” MOVE memory, register void moveToMemFromReg() “10000010” MOVE register, memory void movetoregfrommem() “10000011” MOVE memory, constant void movetomemfromconst() “10000100” MOVE register, constant void movetoregfromconst() “10000101”

The Machine Language Instruction Set

Page 18: Kirk Scott Computer Science The University of Alaska Anchorage

18

The ADD Instruction assembly instruction method in simulation machine instruction   ADD register, register void addDestRegSrcReg() “10000110” ADD memory, register void addToMemFromReg() “10000111” ADD register, memory void addToRegFromMem() “10001000” ADD memory, constant void addToMemFromConst() “10001001” ADD register, constant void addToRegFromConst() “10001010”

Page 19: Kirk Scott Computer Science The University of Alaska Anchorage

19

The SUB Instruction assembly instruction method in simulation machine instruction SUB register, register void subDestRegSrcReg() “10001011” SUB memory, register void subFromMemSrcReg() “10001100” SUB register, memory void subFromRegSrcMem() “10001101” SUB memory, constant void subFromMemSrcConst() “10001110” SUB register, constant void subFromRegSrcConst() “10001111”

Page 20: Kirk Scott Computer Science The University of Alaska Anchorage

20

The JUMP Instruction assembly instruction method in simulation machine instruction JMP unsigned integer void jumpUnconditional() “10010000” JPOS unsigned integer void jumpOnPositive() “10010001” JNEG unsigned integer void jumpOnNegative() “10010010” JZERO unsigned integer void jumpOnZero() “10010011” JOVER unsigned integer void jumpOnOverflow() “10010100”

Page 21: Kirk Scott Computer Science The University of Alaska Anchorage

21

The data declarations come first, then the program code

The program will be loaded at offset 0 Words 0-7 are reserved for data variables

and will be filled with 0’s if there are not that many variables

No program, including data, can be longer than 31 lines

The source file signals termination with a row of asterisks

General Remarks on the Form of Machine Language

Page 22: Kirk Scott Computer Science The University of Alaska Anchorage

22

Data Declaration Line Byte 1: value Bytes 2-4: unused Line of Code Byte 1: instruction Byte 2: operand 1 Byte 3: operand 2 Byte 4: unused

Page 23: Kirk Scott Computer Science The University of Alaska Anchorage

23

The example is a machine language program that sums the first 10 integers

The machine language alone with artificial line breaks and segment labels follows

The *’s are used on input to detect the end of the program.

An Example Machine Language Program

Page 24: Kirk Scott Computer Science The University of Alaska Anchorage

24

data segment   00001011000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000

Page 25: Kirk Scott Computer Science The University of Alaska Anchorage

25

code segment   10000101000001000000000100000000 10000111000000010000010000000000 10001010000001000000000100000000 10000011000000110000000000000000 10001011000000110000010000000000 10010001000010010000000000000000 ********************************

Page 26: Kirk Scott Computer Science The University of Alaska Anchorage

26

/.DATA///

00001011 00000000 00000000 00000000   /LOOPLIM/X0B// loop limit offset 0, value 11   00000000 00000000 00000000 00000000 /ACCUM/X00// accumulator offset 1, value 0

The Example Program Data Segment with Assembly Language Guide

Page 27: Kirk Scott Computer Science The University of Alaska Anchorage

27

/.CODE///

10000101 00000100 00000001 00000000   /MOVE/D/X01/ move reg D, const 1 movetoregfromconst 4, 1   /.LABEL/LOOPTOP//   10000111 00000001 00000100 00000000 /ADD/ACCUM/D/ (LABEL) add data offset 1, reg D addtomemfromreg 1, 4

The Example Program Code Segment with Assembly Language Guide

Page 28: Kirk Scott Computer Science The University of Alaska Anchorage

28

10001010 00000100 00000001 00000000 /ADD/D/X01/ add reg D, 1 addtoregfromconst 4, 1   10000011 00000011 00000000 00000000 /MOVE/C/LOOPLIM/ move reg C, data offset 0 movetoregfrommem 3, 0

Page 29: Kirk Scott Computer Science The University of Alaska Anchorage

29

10001011 00000011 00000100 00000000 /SUB/C/D/ sub reg C, reg D subtractdestregsrcreg 3, 4

10010001 00001001 00000000 00000000   /JPOS/LOOPTOP// Since space is reserved for 8 variables, the first instruction

comes at word 8. jump on positive to “LABEL” jumponpositive 9   ******** ******** ******** ******** /.END///

Page 30: Kirk Scott Computer Science The University of Alaska Anchorage

30

The simulation consists of 4 java files:◦ MachineWord.java◦ Machine.java◦ Osystem.java◦ MachineOSProgram.java

MachineOSProgram contains main()

The Java Files Comprising the Simulation

Page 31: Kirk Scott Computer Science The University of Alaska Anchorage

31

MISC presents these 3 command prompts: rpf (run program file) dmc (dump memory contents) exit

The Command Line Interface

Page 32: Kirk Scott Computer Science The University of Alaska Anchorage

32

rpf = run program file This prompts the user for the machine

language program to run Machine language programs should be text

files

rpf

Page 33: Kirk Scott Computer Science The University of Alaska Anchorage

33

dmc = dump machine contents This prompts the user for the name of the

output file to create This should be a text file MISC has no I/O capabilities You know what a program did by looking at

the dmc file

dmc

Page 34: Kirk Scott Computer Science The University of Alaska Anchorage

34

exit = quit the simulation

exit

Page 35: Kirk Scott Computer Science The University of Alaska Anchorage

35

MachineByte.java MachineWord.java

Machine.java This is the heart of the simulation It contains these critical methods:

◦ totalReset()◦ resetOffsets()◦ takeControl()

A Summary of the Structure of the Java Simulation by Class, Constructor, and Method

Page 36: Kirk Scott Computer Science The University of Alaska Anchorage

36

Osystem.java This has a constructor in which a copy of

the Machine is constructed It contains these critical methods:

◦ runProgramFile()◦ dumpMemoryContents()

Page 37: Kirk Scott Computer Science The University of Alaska Anchorage

37

MachineOSProgram.java This contains the main() method It is the simulation driver In it a copy of the Osystem is constructed It loops, checking for user input from the

command prompt

Page 38: Kirk Scott Computer Science The University of Alaska Anchorage

38

MyTerminalIO This presents the command prompt in a

graphical user interface

Page 39: Kirk Scott Computer Science The University of Alaska Anchorage

39

Part 2. Graphical User Interface Modifications

Page 40: Kirk Scott Computer Science The University of Alaska Anchorage

40

As given so far, the MISC simulation only has a command line interface

The program is an ideal candidate for a graphical user interface

MISC is much easier to use and understand when it is presented visually

Page 41: Kirk Scott Computer Science The University of Alaska Anchorage

41

This section of the overheads outlines a sequence of 10 steps for developing a visual version of the program

A screenshot of the program will be shown with the first 5 steps implemented

Another screenshot will be shown at the end with all of the steps implemented

Page 42: Kirk Scott Computer Science The University of Alaska Anchorage

42

Step 1 Menu Give the application a frame with a menu Have the options to do load, run, dump, and

exit be menu items with associated listeners JFileChooser Use a JFileChooser to handle the information

about file names that has to be passed back and forth for the load and dump commands

Page 43: Kirk Scott Computer Science The University of Alaska Anchorage

43

Step 2 Editable Registers Display the register contents of the machine

in the graphics frame of the application The register representations should be

capable of both input and output JTextFields and JLabels Use JTextFields to represent the registers Label the registers with JLabels

Page 44: Kirk Scott Computer Science The University of Alaska Anchorage

44

Step 3 Stepwise execution Revise MISC so that one machine language

instruction can be executed at a time Update the registers after the execution of

each instruction JButton Implement the execution of a single

instruction through a button click (It could also be done as a menu option)

Page 45: Kirk Scott Computer Science The University of Alaska Anchorage

45

Step 4 Focus Add focus to the application Hitting enter in one register should move

the cursor to the next register Clearing registers Add a ‘clear’ button that will set the

contents of all of the registers to 0 This should not change the loaded program

Page 46: Kirk Scott Computer Science The University of Alaska Anchorage

46

Step 5 Memory Display the contents of the machine’s

memory in the application’s frame JTextArea and scroll bars Display the memory using a JTextArea Memory contents are too large to fit in the

frame at the same time Make sure the JTextArea is contained in

scroll bars

Page 47: Kirk Scott Computer Science The University of Alaska Anchorage

47

Steps 1-5 Screenshot The screenshot on the next overhead gives

some idea of what an implementation of steps 1-5 might look like

Page 48: Kirk Scott Computer Science The University of Alaska Anchorage

48

Page 49: Kirk Scott Computer Science The University of Alaska Anchorage

49

Step 6 Highlight the current instruction Highlight the instruction in the loaded

program that is currently being executed Do this by changing the background color of

that line. JTextComponent These JTextComponent methods are

relevant: selectAll(), cut(), setCaretPosition(), and moveCaretPosition()

Page 50: Kirk Scott Computer Science The University of Alaska Anchorage

50

Step 7 Editable Memory Make memory editable in the frame If the program code loaded in the machine

is altered, then it is the altered version that should run

The original program file in secondary storage should not be changed

Page 51: Kirk Scott Computer Science The University of Alaska Anchorage

51

Step 8 Save and load Add save and load options to the menu Midway through a machine language

program run, between button clicks, it would be possible to save the state of the machine to a file and reload it later to continue the run

If the design is suitably object-oriented, serializability should support this

Page 52: Kirk Scott Computer Science The University of Alaska Anchorage

52

Step 9 Threading Turn this into a threaded application Add a menu option to make more than one

copy of the machine, each in its own frame Add another button, which causes a

program in a frame to run from beginning to end without repeated clicking

Page 53: Kirk Scott Computer Science The University of Alaska Anchorage

53

It should be possible to load and run sumtenV1.txt in multiple frames and see the copies of MISC executing the program in their separate frames at the same time

If things go by so fast that you don’t have time to start a second copy before the first one stops, add a delaying mechanism to the code

Page 54: Kirk Scott Computer Science The University of Alaska Anchorage

54

The screenshot on the next overhead gives some idea of what an implementation would look like after steps 6-9 are accomplished

Steps 6-9 Screenshot

Page 55: Kirk Scott Computer Science The University of Alaska Anchorage

55

Page 56: Kirk Scott Computer Science The University of Alaska Anchorage

56

Step 10 Draw a UML diagram for the final version of

the code…

Page 57: Kirk Scott Computer Science The University of Alaska Anchorage

57

Project Part Dependency Diagram The diagram given on the next overhead

shows the dependency relationships between the different steps

Page 58: Kirk Scott Computer Science The University of Alaska Anchorage

58

1

4

2

9

56

7

3

8

10 Part 10 depends on however many parts you chose to implement.

Page 59: Kirk Scott Computer Science The University of Alaska Anchorage

59

Four aspects of the graphical user interface implementation merit further review:◦ Focus◦ Threading◦ Register editing◦ Memory editing

3. Conclusion

Page 60: Kirk Scott Computer Science The University of Alaska Anchorage

60

Focus in Java has many ramifications It is not always easy to figure out how focus

works in a given application Solving focus in the implementation of a

visual version of MISC means grappling with these issues

Focus

Page 61: Kirk Scott Computer Science The University of Alaska Anchorage

61

Threading is an advanced topic Implementing it in a graphical application is

not easy However, including threading in MISC is

useful It means that a user of MISC can literally

see the alternation between the execution of different copies of a machine language program in different instances of the MISC machine

Threading

Page 62: Kirk Scott Computer Science The University of Alaska Anchorage

62

Step 2: Editable registers Step 3: Stepwise execution These two steps together mean that the

MISC environment can serve as a debugger for MISC machine language programs

Register contents can be changed during the course of a program run

Register Editing

Page 63: Kirk Scott Computer Science The University of Alaska Anchorage

63

Step 7: Editable memory This step means that the MISC environment

can serve as an interactive editing environment for MISC machine language programs

Adding another step so that the current contents of memory could be saved back to secondary storage would complete this aspect of MISC

Memory Editing

Page 64: Kirk Scott Computer Science The University of Alaska Anchorage

64

As noted at the beginning, making MISC visual makes it easier to understand and use

The steps outlined above begin to turn MISC into an integrated development environment for MISC machine language programs

The imagination is the only limit on what other features might be added

MISC Integrated Development Environment

Page 65: Kirk Scott Computer Science The University of Alaska Anchorage

65

The End