Question
Using LC-3 Programming Exercise 1 Use .BLKW to set up a remote array of 10 values, starting at memory location x4000, as in lab 3.
Using LC-3 Programming
Exercise 1
Use .BLKW to set up a remote array of 10 values, starting at memory location x4000, as in lab 3. Now programmatically populate the array with the numbers 0 through 9 (note - NOT the characters '0' through '9'!) i.e. hard-code just the first value (0), then calculate the rest one at a time, storing them in the array as you go. Remember the proper way of setting a register to 0! After you've stored them all, grab the seventh value (i.e. 6) and store it in R2. Clearly, you can't access this location via a label, so you'll need its actual address. How will you obtain that? And how will you use that address to get the value stored there? As always, step through your program and examine the values as they are stored in the array, and examine the final value stored in R2, to make sure your program works as expected.
Exercise 2
You'll notice that Exercise 1 didn't ask you to output to console the array you built. Why not? Because as you know by now, numbers are not characters! So now copy your exercise 1 code into lab4_ex2.asm, and add an output loop, making it output the characters corresponding to the numbers stored in your array.
Exercise 3
Let's try another modification of our well-used array program from Exercise 1: This time, instead of calculating and storing the numbers from 0 to 9 in the array, calculate and store the first ten powers of 2, starting with 20 = 1 in array index 0. Finally, grab the seventh value (26) from the array, and store it in R2. In order to do this, you will have to figure out how to calculate powers of 2. Some hints: Mathematically speaking: How do I obtain 2n+1 if I know 2n? What LC-3 operation could I use to multiply a number by 2? As always, place a breakpoint in your program, and step through it, examining the values as they are being stored in the array, and examine the final value stored in R2, to make sure your program works as expected. Pay attention to both the decimal and hex representations of the values being stored. You already understand that you can't simply output the values in the array to the console as is, so we have to manipulate them somehow to turn them into characters. But this time all but the first four are multi-digit numbers when represented as decimal values, so our trick from the last exercise won't work it can only convert the numbers from 0 to 9 into the single-digit ascii characters '0' through '9'.
Exercise 4
For now, we will instead observe what happens if we attempt to do what we just said can't be done - output the contents of the array "as is", i.e. as if they were ascii codes (which they are not!). Copy your exercise 3 code into your lab4_ex4.asm file, and add a second loop that loads the content of each element of the array into R0 and outputs it to the console using OUT. Now place a breakpoint at the start of your display loop and step through it: You will need to keep an eye on the Console to understand what is going on!!
Please add comments!!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started