1. LC-3 Changes

  1. Removed automatic %dump after assemble
  2. Removed GETC before prompt
  3. New Instructions

2. New Instructions

The 16th instruction (1101) has now been implemented, and in fact, can be changed to be one of a couple of different meanings. By default it is SHIFT.

NOTE: you can only use one MODE when you assemble a program.

2.1 SHIFT

SHIFT SRC, SEXT-IMMEDIATE-BITS

This is the default. SRC is a register to SHIFT, and SEXT-IMMEDIATE-BITS is the number (and direction) of bits to shift.

Examples:

SHIFT R0, #1   ;; Shifts R0 1 bit to left
SHIFT R1, #-2  ;; Shifts R1 2 bits to right

2.1.1 Shift Left

In [1]:
.ORIG x3000
AND R0, R0, 0
ADD R0, R0, 1
SHIFT R0, 1
HALT
.END
Assembled! Use %dis or %dump to examine.
In [2]:
%exe
============================================================
Computation completed
============================================================
Instructions: 4
Cycles: 27 (0.000013 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x0002 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3004 

2.1.2 Shift Right

In [3]:
.ORIG x3000
AND R0, R0, 0
ADD R0, R0, 2
SHIFT R0, -1
HALT
.END
Assembled! Use %dis or %dump to examine.
In [4]:
%exe
============================================================
Computation completed
============================================================
Instructions: 4
Cycles: 27 (0.000013 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x0001 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3004 

2.2 TERMINAL

Instead of SHIFT, the 16th instruction can also be interpreted to be a TERMINAL command. TERMINAL takes a register containing the address of a string representing a terminal screen, and a immediate-mode value indicating whether the screen should be cleared.

General form:

.SET MODE TERMINAL
TERMINAL SRC, IMMEDIATE-CLEAR

Examples:

.SET MODE TERMINAL
TERMINAL R0, 1  ;; use string pointed to in R0 to print, clearing before hand
TERMINAL R1, 0  ;; use string pointed to in R1 to print

2.2.1 PUTS

The old way:

In [1]:
.ORIG x3000
LEA R0, DATA
PUTS
HALT
DATA: .STRINGZ "Hello, World!\n"
.END
Assembled! Use %dis or %dump to examine.
In [2]:
%exe
Hello, World!
============================================================
Computation completed
============================================================
Instructions: 167
Cycles: 1382 (0.000691 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x3003 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3003 

2.2.2 TERMINAL

In [3]:
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
HALT
DATA: .STRINGZ "Hello, World!"
.END
Assembled! Use %dis or %dump to examine.
In [4]:
%exe
Hello, World!
Hello, World!
============================================================
Computation completed
============================================================
Instructions: 4
Cycles: 37 (0.000018 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x3004 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3004 
In [5]:
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
TERMINAL R0, 1
HALT
DATA: .STRINGZ "Hello, World!"
.END
Assembled! Use %dis or %dump to examine.
In [6]:
%exe
Hello, World!
============================================================
Computation completed
============================================================
Instructions: 5
Cycles: 48 (0.000024 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x3005 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3005 
In [ ]:
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
TERMINAL R0, 1
HALT
DATA: .STRINGZ "Hello, World!"
.END
In [7]:
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
;;TERMINAL R0, 0
PUTS
HALT
DATA: .STRINGZ "+-----------------------------------------------------------------------------+\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n+-----------------------------------------------------------------------------+"  
.END
Assembled! Use %dis or %dump to examine.
In [9]:
%%time
%exe
+-----------------------------------------------------------------------------+
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
+-----------------------------------------------------------------------------+============================================================
Computation completed
============================================================
Instructions: 15842
Cycles: 131057 (0.065529 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x3003 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3003 
Time: 1.1079833507537842 seconds.

In [13]:
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
;;PUTS
HALT
DATA: .STRINGZ "+-----------<b style='color: red'>------</b>------------------------------------------------------------+\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n|                                                                             |\n+-----------------------------------------------------------------------------+"
.END
Assembled! Use %dis or %dump to examine.
In [14]:
%%time
%exe
+-----------------------------------------------------------------------------+
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
+-----------------------------------------------------------------------------+
============================================================
Computation completed
============================================================
Instructions: 3
Cycles: 26 (0.000013 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 0 P: 1 
R0: x3003 R1: x0000 R2: x0000 R3: x0000 
R4: x0000 R5: x0000 R6: x0000 R7: x3003 
Time: 0.020509004592895508 seconds.