(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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I've been working on this project about an assembly-language program that prints the binary version of a four numeral decimal number (such as 3241) to the console, I finished the code but when I run it into LC-3 simulator I get his error "Oh no! You've got an error in your assembly code:

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.
Transcribed Image Text: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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education