In: Computer Science
There will be 10 numbers stored contiguously in the computer at location x7000 . Write a complete LC-3 program, starting at location x3000, that will find the location of the smallest number and swap its location with the number in location x7000. For example,
Suppose the following numbers are stored at location x7000:
x7000 123F x7000 0042
x7001 6534 x7001 6534
x7002 300F x7002 300F
x7003 4005 after the program is run, memory x7003 4005
x7004 3F19 would look like----à x7004 3F19
x7005 2DF6 x7005 2DF6
x7006 1200 x7006 1200
x7007 0042 x7007 123F
x7008 12AA x7008 12AA
x7009 54EF x7009 54EF
Note the smallest element occurred at location x7007: the program swapped the contents of location x7007 with location x7000.
You should make NO assumptions about the numbers located at x7000. That is, there may be negative numbers and numbers may repeat.
You should save this code for your next assignment, as we will write a selection sort. This is the beginning of such a program.
-it must be in Lc3 assembly language
PROGRAM:
.ORIG x3000
LD R0,ADDR
LDR R3,R0,#0
ENTER_LOOP
LD R1,I
LD R2,LIMIT
NOT R2,R2
ADD R2,R2,#1
ADD R1,R1,R2
BRzp EXIT_LOOP
LD R0,ADDR
LD R1,I
ADD R0,R0,R1
LDR R4,R0,#0
NOT R4,R4
ADD R4,R4,#1
ADD R5,R3,R4
BRn INCR
NOT R4,R4
ADD R4,R4,#1
ADD R3,R4,#0
ST R1,INDEX
INCR
LD R1,I
ADD R1,R1,#1
ST R1,I
BR ENTER_LOOP
EXIT_LOOP
LD R0,ADDR
LDR R1,R0,#0
LD R2,INDEX
ADD R0,R0,R2
LDR R3,R0,#0
STR R1,R0,#0
LD R0,ADDR
STR R3,R0,#0
HALT
ADDR .FILL x7000
I .FILL #0
LIMIT .FILL #10
INDEX .FILL #0
.END
Please refer to the screenshot of the program for indentation of code:
OUTPUT:
Before execution of code the values in memory are:
After execution of code values in memory are: