Hello I'm a beginner in lc3 assembly language and I have this assignment:
I need to implement the print, the right shift and the shift subroutines showed below, any help of any of these subroutines will be appreciated: (the incomplete code is below at the end)
Also all subroutines must save/restore all working register including R7
A LSHR algorithm is given here: http://users.cis.fiu.edu/~pestaina/RightShift.pdf. Complete the RSHIFT subroutine by implementing the Logical Shift Right Algorithm To test RSHIFT, temporarily replace the JSR SHIFT instruction in MAIN with JSR RSHIFT. The program should now display the original and right-shifted data six times.
Complete the SHIFT subroutine. The datum to be shifted is passed in R0; the value in R1 indicate the shift-type as follows: LSHL LSHR ASHL ASHR CSHL CSHR 0 1 2 3 4 5 .. 0000 .. 0001 .. 0010 .. 0011 .. 0100 ..0101 Hint: the shift direction is always described in R1[0]; arithmetic shifts are indicated by R1[1]; circular shifts are indicated by R1[2]. Hint: All left shifts can be implemented as minor variations of the Logical Shift Left, LSHL. The LSHL can be done by simply adding the datum with itself. Hint: All right shifts can be implemented as variations of the Logical Shift Right, already implemented in your RSHIFT subroutine.
Here’s a trivial print algorithm:
do 16 times
{
output ( Reg[15] ? ‘1’ : ‘0’ );
ShiftLeft( Reg );
}
and this is the program I need to complete
.ORIG x3000
MAIN
LEA R3, DATA ;R3 - Pointer to 1st Test Datum
TEST
LDR R2, R3, #0 ;R2 - Get next Test Datum
BRZ EXIT ; Exit if 0
AND R1, R1, #0 ;R1 - Shift Type initially 0
LEA R5, CAPS ;R5 - Pointer to 1st Caption
NEXT
AND R0, R5, #-1 ;R5 - Display Caption LSHL, etc.
TRAP x22
LD R0, CR_LF
TRAP x21
ADD R0, R2, #0 ; Display Original Datum
JSR PRINT
LD R0, CR_LF
TRAP x21
ADD R0, R2, #0 ; Shift Original Datum
JSR SHIFT ;R0 - Shifted Datum
JSR PRINT ; Display Shifted Datum
LD R0, CR_LF
TRAP x21
ADD R5, R5, #5 ;R5 - Locate next Caption
ADD R1, R1, #1 ;R1 - Sequence to next Shift Type
ADD R4, R1, #-5 ; Test Shift Type
BRNZ NEXT ; Exit if > 5
ADD R3, R3, #1 ;R3 - Locate next Test Datum
BRNZP TEST ; Repeat
EXIT
TRAP x25 ; Halt
;Variables
DATA .FILL x9875 ;Test Datum
.FILL x0000 ;Sentinel
CR_LF .FILL x000A ;New-Line \n
CAPS .STRINGZ "LSHL" ;Captions
.STRINGZ "LSHR"
.STRINGZ "ASHL"
.STRINGZ "ASHR"
.STRINGZ "CSHL"
.STRINGZ "CSHR"
;====================================================================
PRINT ;Display content of R0 in binary
RET
;====================================================================
SHIFT ;Universal Shift Subroutine
; R0 - Datum to be Shifted
; R1 - Shift Type: 000(0) - LSHL - Logical Left
; 001(1) - LSHR - Logical Right
; 010(2) - ASHL - Arithmetic Left
; 011(3) - ASHR - Arithmetic Right
; 100(4) - CSHL - Circular Left
; 101(5) - CSHR - Circular Right
RET
;====================================================================
RSHIFT ;Perform a Logical Shift Right on R0
;Shifted result returned in R0
RET
;====================================================================
.END
I think the "Print" command is supposed to be PUTS. That will print the contents of memory, starting with R0 and ending with a null terminator (I think).