Question

In: Computer Science

There will be 10 numbers stored contiguously in the computer at location x7000 . Write a...

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

Solutions

Expert Solution

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:


Related Solutions

for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
HCS12 Assembly Language: 1. Write a program to convert a decimal number stored at memory location...
HCS12 Assembly Language: 1. Write a program to convert a decimal number stored at memory location $1010 into a binary number. Store the result in memory location $2000
Task 1 Write a program that adds the three numbers stored in data registers at 0x20,...
Task 1 Write a program that adds the three numbers stored in data registers at 0x20, 0x30, and 0x40 and places the sum in data register at 0x50 task 4 Modify the program in Task1, so the program will run in infinite loop by using these following functions: GOTO function BRA function CALL function Simulate your program in PIC18 IDE Simulator and attach a screenshot of your simulation while the program is running.
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory...
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory using the algorithm below. Hand trace (execute) the program showing the changes made to all affected registers and memory locations. Max = a(1) For i = n to N If max < a(i) then max = a(i) Next i
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10...
We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different “digits” {0,1,...,9}. Sometimes though it is useful to write numbers in hexadecimal or base 16. Now there are 16 distinct digits that can be used to form numbers: {0,1,...,9,A,B,C,D,E,F}. So for example, a 3 digit hexadecimal number might be 3B8. (a) How many 2-digit hexadecimals are there in which the first digit is E or F? Explain your answer in terms of the...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write 2 detailed samples of scary text-based computer games. The location of your game could be...
Write 2 detailed samples of scary text-based computer games. The location of your game could be a place that truly exists (possibly include research). Exclude graphic content. Remember to give choices to the player during the game. The 2 text based games must be invented by you and list scene by scene the options given to the player. Brief example of what the samples should look like: There is an old, dark castle in front of you, will you go...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT