![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS240 Computer Organization / 2015-Fall / Notes |
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.
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
.ORIG x3000
AND R0, R0, 0
ADD R0, R0, 1
SHIFT R0, 1
HALT
.END
%exe
.ORIG x3000
AND R0, R0, 0
ADD R0, R0, 2
SHIFT R0, -1
HALT
.END
%exe
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
The old way:
.ORIG x3000
LEA R0, DATA
PUTS
HALT
DATA: .STRINGZ "Hello, World!\n"
.END
%exe
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
HALT
DATA: .STRINGZ "Hello, World!"
.END
%exe
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
TERMINAL R0, 1
HALT
DATA: .STRINGZ "Hello, World!"
.END
%exe
.ORIG x3000
.SET MODE TERMINAL
LEA R0, DATA
TERMINAL R0, 0
TERMINAL R0, 0
TERMINAL R0, 1
HALT
DATA: .STRINGZ "Hello, World!"
.END
.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
%%time
%exe
.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
%%time
%exe