Editing Main Memory


You can edit the contents of the memory cells displayed in the memory window of the simulator. You can choose the cell you want to edit by clicking on it with the mouse or using the Tab and/or Shift-Tab keystrokes. The memory editor only recognizes decimal integers. An error dialog will be displayed if the memory cell contains an invalid entry.

 

When the memory window is displaying: Cell contents must be in the range:
Bytes 0 to 255
Words -2147483648 to 2147483647

 

Note: Editing the main memory will not alter the contents of the disassembler window. The disassembled code is generated only when a machine language program is loaded into memory (from a file or by the assembler).

 

Editing Data

The most common reason for editing main memory is to alter data values.

 1. Enter the following program in the source code editor.

.main
    .var a b sum .end-var // Declare three variables

    // Find sum = a + b
    iload a
    iload b
    iadd
    istore sum
    halt
.end-main

 2. Clear the memory of the computer (Memory menu; Clear Memory option).

 3. Assemble this program (F2). If you do not want to save the source code in a file, just cancel the save dialog. The assembled program will still be loaded into memory.

 4. Click the Computer Simulator tab and then click the Run button.

 5. Click the Goto LV button below the memory window. The memory display should look as illustrated below (except for the red labels which identify the location of each variable):

The variables a and b were not initialized by the program. Consequently, their initial values depend on what was last stored in the corresponding memory locations. Since we cleared memory before assembling the program, both variables had an initial value of zero and the calculated sum was also zero. That's not very interesting.

 6. Edit main memory as shown below:

 7. Reset the computer and Run the program again (with these new data values).

 8. Click the Goto LV button. Now you will see:

 

Editing a Machine Language Program

Another reason to edit main memory is to modify a machine language program that has been loaded into memory.

 1. Enter the following program in the source code editor:

.main
    bipush 4  // Push 4 onto the stack
    bipush 6  // Push 6 onto the stack
    iadd      // Replace top two values with their sum
    halt
.end-main

 2. Clear the memory of the computer (Memory menu; Clear Memory option).

 3. Assemble this program (F2). If you do not want to save the source code in a file, just cancel the save dialog. The assembled program will still be loaded into memory.

 4. Reset the computer and Run the program.

 5. Click the Goto SP button and verify that the value on the top of the stack is 10.

 6. Click the Go to: button with an address of zero in the text box. Make sure the radio button Display Bytes is selected. The memory window will display bytes starting at address zero:

 7. Modify the operand of the first bipush instruction by setting it to 20.

 8. Reset the computer and Run the program again. Verify that the value on the top of the stack is now 26 (20 + 6).

 9. Change the opcode at address 4 by setting it to 100 (the decimal opcode for ISUB):

 10. Reset the computer and Run the program again. Verify that the value on the top of the stack is now 14 (20 - 6).

 

Writing Machine Language Programs

The preferred way to create a machine language program is to write the program in assembly language and let the assembler generate the machine language code. If you want to, you can write simple machine language programs using just the memory editor. However, you can not save programs written in this way.

 1. Clear the memory.

 2. Make sure the memory is displaying bytes (Display Bytes) and enter this machine language program:

 3. Reset the computer and run the program. You should see the word "Hi" displayed in the input/output window:

The corresponding assembly language program is given here:

.main
    bipush 'H'
    out
    bipush 'i'
    out
    halt
.end-main