Part 2 - Copy Array In this problem, you will write a Simple Machine program that copies an array. Start by copying the starter file to your current directory: cp /pub/cs/jpotter/cs270/sim/copy_array Take a look at the starter file. Note that it has each address from Ox0 to Ox22 filled in. Your job is to replace as many lines at the beginning as you need to solve the problem. You should not add any lines, except possibly at the very end Your program should implement the following algorithm, given in a high-level language: for (int i = e; 〈 ARRAY-SIZE; i++) OTHER-ARRAY[i] ARRAY[i]; = Note that in the data section of the starter file, ARRAY SIZE is at address Ox20 (decimal 32). Ive also put a variable called TEMP at address Ox21 (decimal 33). Each time you put an array value into the accumulator, youll need to store it in TEMP so that you can start computing the address in OTHER ARRAY where youll put the value. Once you have the address register set to the address in OTHER ARRAY, you can load TEMP back into the accumulator and store it to the address in the address register. It might help to think of the code like this: for (int 1-0; 1 < ARRAY-SIZE ; i++) TEMP ARRAY[i]; OTHER-ARRAY[1] = TEMP ; ARRAY starts at address 0x22 (decimal 34). OTHER ARRAY starts at address Ox32 (decimal 50). You can assume that ARRAY_SIZE will never be larger than 16 (so the first array doesnt overrun the second array). The autograder will assume that these variables are at these locations. Your program must go through ARRAY and copy the values into OTHER_ARRAY.

The starter file is below:

####################################

# Name:

#

#####################################

#

# This is the starter code for

# the “copy array” problem in

# assignment 4. Note that

# the first 32 lines contain the

# halt instruction. Your job is to

# replace instructions starting at

# the beginning with your own

# instructions to solve part 1. You

# should need fewer than 32

# instructions, so you shouldn’t

# have to worry about running out

# of space.

#

# The data for this program starts

# at address 0x20 (or 32 in

# decimal). DO NOT ALTER THE

# LOCATION OF THE DATA GIVEN. The

# autograder will rely on ARRAY_SIZE

# being at address 0x20, ARRAY

# starting at address 0x22, and

# OTHER_ARRAY starting at

# address 0x32.

#

#####################################

#

# Original C Code

# —————–

# for (int i = 0; i < ARRAY_SIZE; i++)

# {

# OTHER_ARRAY[i] = ARRAY[i];

# }

#

# OR, a better way to think about it:

#

# for (int i = 0; i < ARRAY_SIZE; i++)

# {

# TEMP = ARRAY[i];

# OTHER_ARRAY[i] = TEMP;

# }

#

#####################################

#

# Your program starts here.

0x0 # (ADDR=0x0)

0x0 # (ADDR=0x1)

0x0 # …

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0 # (ADDR=0xA)

0x0

0x0

0x0

0x0

0x0

0x0 # (ADDR=0x10)

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0 # (ADDR=0x1f)

# Data starts here.

0x0005 # (ADDR=0x20) ARRAY_SIZE

0x0000 # (ADDR=0x21) TEMP

0x0006 # (ADDR=0x22) ARRAY[0]

0xffff # (ADDR=0x23) ARRAY[1]

0xfff7 # (ADDR=0x24) ARRAY[2]

0x0002 # (ADDR=0x25) ARRAY[3]

0x0010 # (ADDR=0x26) ARRAY[4]

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0 # (ADDR=0x32) OTHER_ARRAY[0]

0x0 # (ADDR=0x33) OTHER_ARRAY[1]

0x0 # (ADDR=0x34) OTHER_ARRAY[2]

0x0 # (ADDR=0x35) OTHER_ARRAY[3]

0x0 # (ADDR=0x36) OTHER_ARRAY[4]

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

0x0

Part 2 – Copy Array In this problem, you will write a Simple Machine program that copies an array. Start by copying the starter file to your current directory: cp /pub/cs/jpotter/cs270/sim/copy_array Take a look at the starter file. Note that it has each address from Ox0 to Ox22 filled in. Your job is to replace as many lines at the beginning as you need to solve the problem. You should not add any lines, except possibly at the very end Your program should implement the following algorithm, given in a high-level language: for (int i = e; 〈 ARRAY-SIZE; i++) OTHER-ARRAY[i] ARRAY[i]; = Note that in the data section of the starter file, ARRAY SIZE is at address Ox20 (decimal 32). I’ve also put a variable called TEMP at address Ox21 (decimal 33). Each time you put an array value into the accumulator, you’ll need to store it in TEMP so that you can start computing the address in OTHER ARRAY where you’ll put the value. Once you have the address register set to the address in OTHER ARRAY, you can load TEMP back into the accumulator and store it to the address in the address register. It might help to think of the code like this: for (int 1-0; 1 Show transcribed image text