Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objective The purpose of this assignment is to give you more practice with 1/0, and with left-shifting, aka multiplying by 2, and useful 2's complement
Objective The purpose of this assignment is to give you more practice with 1/0, and with left-shifting, aka multiplying by 2, and useful 2's complement logic. High Level Description Store a number to the memory address specified in your assn 3 template. In your program, load that number in a register, and display it to the console as 16-bit two's complement binary (i.e. display the binary value stored in the register, as a sequence of 16 ascii 'l' and 'O' characters). Note: Valid numbers are [#-32768, #32767] (decimal) or [X0000, XFFFF] (hex) Your Tasks You do not yet know how to take a multi-digit decimal number from user ascii input and convert it to binary, so for this assignment you are going to let the assembler do that part for you: you will use the .FILL pseudo-op to take a literal (decimal or hex, as you wish) and translate it into 16-bit two's complement binary, which will be stored in the indicated memory location; and then you will Load that value from memory into a register. You MUST use the provided assn3.asm template to set this up: it ensures that the number to be converted is always stored in the same location (the memory address specified in your template) so we can test your work; make sure you fully understand the code fragment we provide. At this point, your value will be stored in, say, R1: it is now your job to identify the l's and O's from the number and print them out to the console one by one, from left (the leading bit, aka the leftmost bit, aka the most significant bit, aka bit 15) to right (the trailing bit, aka the rightmost bit, aka the least significant bit, aka bit 0). Important things to consider: Recall the difference between a positive number and a negative number in 2's complement binary: if the most significant bit (MSB) is 0, the number is considered positive (or zero); if it is 1, the number is negative. The Branch instruction has parameters (n, z, p) which tell it to check whether the LMR (Last Modified Register) is negative, zero, or positive (or any combination thereof). Hint: what can you say about the msb of the LMR if the n branch is taken? Review the workings of the NZP condition codes and the BR instruction here. Once you are done inspecting the MSB and printing the corresponding ascii 'O' or '1', how would you shift the next bit into its place so you could perform the next iteration? Hint: the answer is in the objectives! Pseudocode: for(i = 15 downto): if (msb is a 1): print a 1 else: print a shift left Note on creating LC-3 "control structures" See here for tips on creating LC-3 versions of the branch and loop control structures you are familiar with from C++ (Resources -> LC-3 Resources -> LC3 Assembly Language -> Control Structures in LC3) Expected/ Sample output In this assignment, your output will simply be the contents of R1, printed out as 16 ascii 1's and O's, grouped into packets of 4, separated by spaces (as always, newline terminated, but with NO terminating space!) So if the hard coded value was XABCD, your output will be: 1010 1011 1100 1101 LC-3 Console Output from the machine will appear here. In the box below you can specify input. Enter text beforehand, or type while the program is running. Specify bulk input by pasting 1010 1011 1100 1101 (The value stored to memory with .FILL was XABCD) Note: 1. There are spaces after the first three "packets" of 4 bits, but no space character at the end! 2. There is a newline after the output - again, there is NO space before the newline 3. You must use the memory address specified in your template to hold the value to be output. Objective The purpose of this assignment is to give you more practice with 1/0, and with left-shifting, aka multiplying by 2, and useful 2's complement logic. High Level Description Store a number to the memory address specified in your assn 3 template. In your program, load that number in a register, and display it to the console as 16-bit two's complement binary (i.e. display the binary value stored in the register, as a sequence of 16 ascii 'l' and 'O' characters). Note: Valid numbers are [#-32768, #32767] (decimal) or [X0000, XFFFF] (hex) Your Tasks You do not yet know how to take a multi-digit decimal number from user ascii input and convert it to binary, so for this assignment you are going to let the assembler do that part for you: you will use the .FILL pseudo-op to take a literal (decimal or hex, as you wish) and translate it into 16-bit two's complement binary, which will be stored in the indicated memory location; and then you will Load that value from memory into a register. You MUST use the provided assn3.asm template to set this up: it ensures that the number to be converted is always stored in the same location (the memory address specified in your template) so we can test your work; make sure you fully understand the code fragment we provide. At this point, your value will be stored in, say, R1: it is now your job to identify the l's and O's from the number and print them out to the console one by one, from left (the leading bit, aka the leftmost bit, aka the most significant bit, aka bit 15) to right (the trailing bit, aka the rightmost bit, aka the least significant bit, aka bit 0). Important things to consider: Recall the difference between a positive number and a negative number in 2's complement binary: if the most significant bit (MSB) is 0, the number is considered positive (or zero); if it is 1, the number is negative. The Branch instruction has parameters (n, z, p) which tell it to check whether the LMR (Last Modified Register) is negative, zero, or positive (or any combination thereof). Hint: what can you say about the msb of the LMR if the n branch is taken? Review the workings of the NZP condition codes and the BR instruction here. Once you are done inspecting the MSB and printing the corresponding ascii 'O' or '1', how would you shift the next bit into its place so you could perform the next iteration? Hint: the answer is in the objectives! Pseudocode: for(i = 15 downto): if (msb is a 1): print a 1 else: print a shift left Note on creating LC-3 "control structures" See here for tips on creating LC-3 versions of the branch and loop control structures you are familiar with from C++ (Resources -> LC-3 Resources -> LC3 Assembly Language -> Control Structures in LC3) Expected/ Sample output In this assignment, your output will simply be the contents of R1, printed out as 16 ascii 1's and O's, grouped into packets of 4, separated by spaces (as always, newline terminated, but with NO terminating space!) So if the hard coded value was XABCD, your output will be: 1010 1011 1100 1101 LC-3 Console Output from the machine will appear here. In the box below you can specify input. Enter text beforehand, or type while the program is running. Specify bulk input by pasting 1010 1011 1100 1101 (The value stored to memory with .FILL was XABCD) Note: 1. There are spaces after the first three "packets" of 4 bits, but no space character at the end! 2. There is a newline after the output - again, there is NO space before the newline 3. You must use the memory address specified in your template to hold the value to be output
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