Computer Science Homework Help

Assembly Language Code

 

Here is the assignment. If you have any questions or if you need anything, please let me know. I need it to be done with the extra credit. Thank you.

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 😉