(1) Write an assembly-language program that prints the binary version of a four numeral decimal number (such as 3241) to the console. The number should be stored as data in the program with the label: NUMBER. In order to do this, you need to find the binary bits of the number one by one. This can be done by ANDing the number with a mask (a binary num- ber with only one nonzero bit). For example, the following 16-bit mask can be used to pick out whether the bit in the 4s-place-value-location is a one or a zero: 0000000000000100 Here is what must be done and some hints about how to do it: • Find the 16 bits, each a zero or a one, which represent the number via a loop starting with bit 1 and ending with bit 15. This can be done using a series of masks. • Start the loop with the mask for the bit in the 1s place. This mask equals the value 1. Change the mask on each iteration of the loop to the mask for next bit by using the fact that the next mask needed will equal twice the previous mask. What is an LC-3 instruction which doubles a number? • When you find a bit in a given iteration of the loop save the ASCII code for that bit in a sequence of 16 memory cells with the number 0 at the end. These data-cells can be reserved with a .BLKW 16 directive followed by a .FILL #0 directive. . Once the binary numerals for all the bits have been found and saved, use puts to print the binary representation of the number.
I've been working on this project about an assembly-language
at line 16: immediate field is out of range: expected value to fit in 5 bits (i.e., to be between -16 and 15, inclusive), but found 48" I tried to changed the numbers but it didn't work I just need help solving this error so it's able to run into the simulator and prints the output into the console here is the link of the simulator I'm using and my code:
link: https://wchargin.com/lc3web/
Code:
;Kevin Hernandez
;assembly3.asm A) BINARY TO ASCII
;Lavels OPCODE OPERANDS ;Line up the columns
.ORIG x3000
;data section
NUMBER .FILL #3241 ;This number is store in NUMBER
BIN_REP .BLKW #16 ;This is 16-bit
;code section
LD R1, NUMBER ;LOADING THE NUMBER INTO R1
AND R2, R2, #1 ;ININTIALIZE THE MASK
LOOP AND R3, R1, R2
ADD R3, R3, #-3 ;CONVERT THE BIT TO ASCII
ADD R3, R3, R3
ADD R3, R3, #48 ;THE ONLY WAY THIS CODE GOES THROUGHT IF I CHANGE IT THE RANGE TO 12
;BUT IT DOES NOT PRINT ANTHING
ST R3, BIN_REP ;STORING THE ASCII INTO THE NEXT MEMORY CELL
ADD R2, R2, R2 ;DOUBLE MASK
BRzp LOOP ;FINISH LOOPING AFTER ALL 16 BITS HAVE BEEN PROCESSED
;PRINTING
LEA R0, BIN_REP
PUTS
HALT
.END
![Part A (integer to binary numerals)
(1) Write an assembly-language program that prints the binary version of a
four numeral decimal number (such as 3241) to the console. The number
should be stored as data in the program with the label: NUMBER.
In order to do this, you need to find the binary bits of the number one by
one. This can be done by ANDing the number with a mask (a binary num-
ber with only one nonzero bit). For example, the following 16-bit mask
can be used to pick out whether the bit in the 4s-place-value-location is
a one or a zero:
0000000000000100
Here is what must be done and some hints about how to do it:
• Find the 16 bits, each a zero or a one, which represent the number
via a loop starting with bit 1 and ending with bit 15. This can be
done using a series of masks.
• Start the loop with the mask for the bit in the 1s place. This mask
equals the value 1. Change the mask on each iteration of the loop to
the mask for next bit by using the fact that the next mask needed will
equal twice the previous mask. What is an LC-3 instruction which
doubles a number?
• When you find a bit in a given iteration of the loop save the ASCII
code for that bit in a sequence of 16 memory cells with the number
0 at the end.
. These data-cells can be reserved with a .BLKW 16 directive followed
by a .FILL #0 directive.
Once the binary numerals for all the bits have been found and saved,
use puts to print the binary representation of the number.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5380575a-a3d1-4932-bbef-eddd3d1068fa%2F9323dc3f-3ad3-46d4-8755-149874f08697%2Ftqhuss_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)