From c9964a669394095aff8ebfb4cd18eb2e6ca0c774 Mon Sep 17 00:00:00 2001 From: "thomas@cs.ru.nl" Date: Tue, 14 Dec 2010 13:34:48 +0000 Subject: [PATCH] * Added short info on heap and heappointer to info * Consistent usage of 'stack pointer' vs 'stackpointer' (and alike) * Start directory for opening files is location of .jar and not the user's home directory * Fixed structure comments for STMH instructions with size 1 --- src/Help/ssmhelp.prop | 17 +++++++++++------ src/Help/ssminstrhelp.prop | 2 +- src/nl/uu/cs/ssm/Machine.java | 8 ++++++-- src/nl/uu/cs/ssm/Registers.java | 6 +++--- src/nl/uu/cs/ssmui/SSMRunner.java | 4 ++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Help/ssmhelp.prop b/src/Help/ssmhelp.prop index dbbc481..80c2cc0 100755 --- a/src/Help/ssmhelp.prop +++ b/src/Help/ssmhelp.prop @@ -1,17 +1,20 @@ # General help info for Simple Stack Machine -registers=Eight registers are available, some of which have a specific purpose. A register is private location in a processor, often faster accessible then external memory. Currently the Program Counter (PC), Stack Pointer (SP), Mark Pointer (MP) and Return Register (RR) as well as freely usable scratch registers are available, respectively identified by numbers 0..7. Registers are identified by the name R, where is the register number. Register with a specific purpose are also named with the name indicating their purpose. +registers=Eight registers are available, some of which have a specific purpose. A register is private location in a processor, often faster accessible then external memory. Currently the programcounter (PC), stackpointer (SP), markpointer (MP), heappointer (HP), and return register (RR) as well as freely usable scratch registers are available, respectively identified by numbers 0..7. Registers are identified by the name R, where is the register number. Register with a specific purpose are also named with the name indicating their purpose. -PC=The Program Counter (PC) is used to remember what the current next instruction is. It contains the address (i.e. points to) the location of the next instruction. The machine fetches an instruction from the location pointed to by the PC. After each fetch it is automatically updated to point to the next instruction. +PC=The programcounter (PC) is used to remember what the current next instruction is. It contains the address (i.e. points to) the location of the next instruction. The machine fetches an instruction from the location pointed to by the PC. After each fetch it is automatically updated to point to the next instruction. programcounter=@PC -SP=The Stack Pointer (SP) is used to push and pop values for usage in expression evaluation. The Stack is also used to store variables. These are often accessed via the MP. +SP=The stackpointer (SP) is used to push and pop values for usage in expression evaluation. The stack is also used to store variables. These are often accessed via the MP. stackpointer=@SP -MP=The Mark Pointer (MP) is used to access local variables, allocated on the stack. Each variable is accessed using a displacement relative to the MP. +MP=The markpointer (MP) is used to access local variables, allocated on the stack. Each variable is accessed using a displacement relative to the MP. markpointer=@MP -RR=The Return Register (RR) is used to return a value without placing it on a stack. Strictly seen this is not necessary but a convenience, since values also can be passed via the stack. +HP=The heappointer (HP) is used to remember the next free address of the heap. After every store to the heap, the heappointer is incremented with the size of stored values. +heappointer=@HP + +RR=The return register (RR) is used to return a value without placing it on a stack. Strictly seen this is not necessary but a convenience, since values also can be passed via the stack. return register=@RR instruction=An instruction is an encoding of some operation, executed in the machine. A set of instructions stored in memory is called the code. Some instructions have inline operands, that is, after their location in the code an extra operand is stored, a constant, e.g. in "ldc 1". In pre/post conditions this location is indicated by M[PCpre+1] since it can be found on that location. The behavior of an instruction is both informally described as well as using pre/postcondifitions. @@ -20,9 +23,11 @@ memory=Memory stores words. A word is an 32 bits integer. Currently only a limit stack=Stack is the part of memory used to store values needed for evaluating expressions. The stack is located after the code and grows from lower addresses to higher ones. +heap=Heap is the part of memory used to store composite values. The heap is located after the stack and grows from lower addresses to higher ones. + code=Code is the part of memory used to store instructions. It starts at address 0. -help=The Simple Stack Runner executes instructions for a hypothetical (and thus simple) machine. See memory, registers, syntax, instruction as starting points for help. +help=The Simple Stack Machine Interpreter executes instructions for a hypothetical (and thus simple) machine. See memory, registers, syntax, instruction as starting points for help. syntax=Syntax of instructions (as loaded from file) is: (label:)? (instr arg*)?. In other words, an (optional) instruction preceded by an (optional) label and followed by an argument if required. Comment may start with ";" or "//" (Java/C++ style) and ends at the end of the line. This characters are interpreted as start of comment. A label may be used as an argument. Example: "l1: beq l1 ; comment". diff --git a/src/Help/ssminstrhelp.prop b/src/Help/ssminstrhelp.prop index 07fdc3b..21ce199 100755 --- a/src/Help/ssminstrhelp.prop +++ b/src/Help/ssminstrhelp.prop @@ -64,7 +64,7 @@ stma_descr=Store Multiple via Address. Pops values from the stack and stores it stma_prepost=displ = M_pre[PC_pre + 1], size = M_pre[PC_pre + 2], SP_post = SP_pre - size - 1, M_post[M_pre[SP_pre] + displ .. M_pre[SP_pre] + displ + size - 1] = M_pre[SP_post + 1 .. SP_post + size] stma_example=none -ldr_descr=Load Register. Pushes a value from a register. Registers 0, 1, 2 and 3 are called PC (program counter), SP (stack pointer), MP (mark pointer) and RR (return register) respectively. +ldr_descr=Load Register. Pushes a value from a register. Registers 0, 1, 2 and 3 are called PC (programcounter), SP (stackpointer), MP (markpointer) and RR (return register) respectively. ldr_prepost=SP_post = SP_pre + 1, M_post[SP_post] = REG_pre[ M_pre[PC_pre+1] ] ldr_example=ldr RR ; decrement register, ldc 1, sub, str RR diff --git a/src/nl/uu/cs/ssm/Machine.java b/src/nl/uu/cs/ssm/Machine.java index c250f22..6e0eb05 100755 --- a/src/nl/uu/cs/ssm/Machine.java +++ b/src/nl/uu/cs/ssm/Machine.java @@ -512,8 +512,12 @@ public class Machine int endAddr = beginAddr + size - 1; registers.adjustHP(size); popMultiple(beginAddr, size); - memory.setAnnotationAt(beginAddr, new MemoryAnnotation("begin", null)); - memory.setAnnotationAt(endAddr, new MemoryAnnotation("end", null)); + if(size == 1) { + memory.setAnnotationAt(beginAddr, new MemoryAnnotation("begin / end", null)); + } else { + memory.setAnnotationAt(beginAddr, new MemoryAnnotation("begin", null)); + memory.setAnnotationAt(endAddr, new MemoryAnnotation("end", null)); + } push(endAddr); break; diff --git a/src/nl/uu/cs/ssm/Registers.java b/src/nl/uu/cs/ssm/Registers.java index 49e3b32..8df21de 100755 --- a/src/nl/uu/cs/ssm/Registers.java +++ b/src/nl/uu/cs/ssm/Registers.java @@ -17,14 +17,14 @@ public class Registers extends AbstractMemoryCellModel public static final int PC = 0 ; public static final int SP = 1 ; public static final int MP = 2 ; - //public static final int RR = 3 ; - public static final int HP = 4 ; + public static final int HP = 3 ; + //public static final int RR = 4 ; private static final int nrRegs = 8 ; private static final String[] regNames = { "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7" } ; - private static final String[] regNamesAlias = { "PC", "SP", "MP", "RR", "HP" } ; + private static final String[] regNamesAlias = { "PC", "SP", "MP", "HP", "RR" } ; //private MemoryCell cells[] ; private int cells[] ; diff --git a/src/nl/uu/cs/ssmui/SSMRunner.java b/src/nl/uu/cs/ssmui/SSMRunner.java index d0ba8e7..24bcdf1 100755 --- a/src/nl/uu/cs/ssmui/SSMRunner.java +++ b/src/nl/uu/cs/ssmui/SSMRunner.java @@ -315,6 +315,7 @@ public class SSMRunner extends JFrame statusScrollPane.setBorder(createTitledBorder("Status")); statusTable.setVisible(true); statusTable.setFont(null); + statusTable.setPreferredScrollableViewportSize(new java.awt.Dimension(1200, 40)); outputScrollPane.setVisible(true); outputScrollPane.setFont(null); outputScrollPane.setBorder(createTitledBorder("Output")); @@ -815,6 +816,9 @@ public class SSMRunner extends JFrame public void tbLoadButtonActionPerformed(java.awt.event.ActionEvent e) { JFileChooser chooser = new JFileChooser( recentLoadedFile ) ; + if (recentLoadedFile == null) { + chooser.setCurrentDirectory(new File (".")); + } Utils.ExtensionFileFilter ff = new Utils.ExtensionFileFilter( "ssm" ) ; chooser.setFileFilter( ff ) ; if( chooser.showOpenDialog( this ) == JFileChooser.APPROVE_OPTION ) -- GitLab