IN LC-3 Code Exercise 1 Recall that exercise 4 from last week created an array of the
Question:
IN LC-3 Code
Exercise 1
Recall that exercise 4 from last week created an array of the first 10 powers of 2 {20 , 21 , 22 , ..., 29 }, and then attempted to print these values to console as though they were ascii characters - with interesting results! But then in programming assignment 3, you figured out how to take the 16-bit value in a register and print to console the corresponding 16 ascii 1's and 0's.
Your first lab 5 exercise is to take your assn 3 code and turn it into a subroutine:
Copy your lab4 ex. 4 code into lab5_ex1.asm Now take your assn 3 code and modify it as needed to transform it into a subroutine. Add it into your lab5_ex1.asm file, with its own .orig Be sure to adhere to the structure described above. Finally, inside the display loop in the original lab4_ex4 code, replace OUT with an invocation of your new subroutine, passing in each power of 2 in turn. The end result will be 10 lines of output (because the subroutine will be invoked 10 times, once per iteration), representing the first 10 powers of 2 as 16-bit binary numbers (displayed, of course, as ascii 1's and 0's).
-----------------------------------------------------------------------------------------------------------------------
This is my Lab4 Ex. 4 Code...
.ORIG x3000 ;=========== AND R0,R0,#0 AND R1,R1,#0 AND R2,R2,#0 AND R4,R4,#0 AND R6,R6,#0 ;========================= ;CODE HERE================ ;========================= LD R1,COUNTER LD R2,PTR LD R0,ZERO STR R0,R2,#0 ADD R2,R2,#1 ADD R0,R0,#2 STR R0,R2,#0 ADD R3,R3,#2
LD R1,COUNTER
LOOP ADD R2,R2,#1 ADD R0,R0,R0 STR R0,R2,#0 ADD R1,R1,#-1 BRp LOOP LD R1,PTR ADD R1,R1,#6 LDR R2,R1,#0
LD R2,PTR LD R1,TEN LD R3,OFF_SET OUTPUT_LOOP LDR R0,R2,#0 ADD R0,R0,R3 OUT ADD R2,R2,#1 ADD R1,R1,#-1 BRp OUTPUT_LOOP HALT ;======================== ;LOCAL DATA PTR .FILL x4000 ;======================== ZERO .FILL #0 COUNTER .FILL #8 OFF_SET .FILL x30 TEN .FILL #10 .end .ORIG x4000 ARRAY_PTR .BLKW #10 .end
-----------------------------------------------------------------------------------------------------------------------
This is my assn 3 Code...
.ORIG x3000 ;------------- ;Instructions ;------------- LD R6, Value_ptr LDR R1, R6, #0 ;------------------------------- ;INSERT CODE STARTING FROM HERE ;--------------------------------
LD R2, DEC_4 BIT_LOOP LD R3, DEC_4 INNER_BIT_LOOP LD R0, HEX_30 LD R5, LEAD_1 AND R5, R5, R1 BRn PRINT_1 PRINT_0 OUT BR END_PRINT PRINT_1 ADD R0, R0, #1 OUT END_PRINT ADD R1, R1, R1 ADD R3, R3, #-1 BRp INNER_BIT_LOOP END_INNER_BIT_LOOP
ADD R2, R2, #-1 BRz END_SEGMENTS
LD R0, SPACE OUT BR BIT_LOOP END_SEGMENTS
LD R0, NEWLINE OUT
HALT ;--------------- ;Data ;--------------- Value_ptr .FILL xCA01 NEWLINE .FILL x0A DEC_4 .FILL #4 SPACE .FILL #32 CHARACTER .FILL x30 HEX_30 .FILL x30 LEAD_1 .FILL x8000 .END
.ORIG xCA01 Value .FILL xABCD ;--------------- ;END of PROGRAM ;--------------- .END