Write an LC-3 assembly language program that counts the number of 1s in the value stored in R0 and stores the result in R1. For example, if R0 contains XXXXXXXXXXx1370), then after the program...

1 answer below »

Write an LC-3 assembly language program that counts the number of 1s in the value stored in R0 and stores the result in R1. For example, if R0 contains 0001001101110000 (x1370), then after the program executes, the value stored in R1 would be 0000000000000110 (decimal 6)




Here are some hints from my solution:



ORIG x3000


AND R5, R5, #0


ADD R5, R5, #1 ;R5 will act as a mask


AND R1, R1, #0 ;zero out the result register


AND R2, R2, #0 ;R2 will act as a counter


LD R3, NegSixt


MskLoop AND R4, R0, R5 ;mask off the bit


Add code here... if you want more than a 0 ;-)


EXTRA CREDIT


Solicit the number to be inspected via the keyboard.


10 points for a single digit (e.g. 5) decimal number, which must be converted to binary.


20 points for a two digit (e.g. 55) decimal number, which must be converted to binary.



Answered Same DayOct 31, 2021

Answer To: Write an LC-3 assembly language program that counts the number of 1s in the value stored in R0 and...

Swapnil answered on Oct 31 2021
125 Votes
95072/Solution.asm
.ORIG x3000
AND R5, R5, #0
ADD R5, R5, #1
AND R1, R1, #0
AND R2, R2, #0

LD R3, NegSixt
MskLoop AND R4, R0, R5
ADD R1, R1, #1
NotOne ADD R5, R5, R5
ADD R2, R2, #1
ADD R6, R2, R3
BRn MskLoop
HALT
NegSixt .FILL #-16...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here