I'm trying to write a simple program that takes a 16-bit integer from Data1, counts how many bits are 1-bits, and then prints the result to the screen. I'm quite certain my code should do the trick, but for some reason the output I get is a little box symbol, instead of the actual integer value. Does anyone know why I'm getting this output and how I can change it?? This is the code I have:
.orig x3000 ;start at address x3000 LD R1, Data1 ;load R1 with Data1 AND R2, R2, #0 ;clear R2 ADD R2, R2, #1 ;set R2 to 1 ;R2 will be compared with the data ;value to see if the bit is 1 AND R3, R3, #0 ;clear R3 ;R3 will be used as the counter AND R4, R4, #0 ;R4 will hold the answer while ADD R3, R3, #1 ;add 1 to the counter AND R0, R0, #0 AND R0, R1, R2 ;compare R1 and R2 brp yes ;if the bit is 1, goto yes no ADD R2, R2, R2 ;shift bits left br check ;skip over yes yes ADD R4, R4, #1 ;increase the counter br no ;continue check AND R0, R0, #0 ADD R0, R3, #-16 ;if counter is still under 16 brn while endwhile LEA R0, msg ;load message PUTS ;print message AND R0, R0, #0 ADD R0, R4, #0 ;put R4 (answer) in R0 OUT ;print it to screen HALT Data1 .FILL x0002 ;this variable changes msg .STRINGZ "\nNumber of non-zero bits: " .end
The output I should get is:
Number of non-zero bits: 1
(Since the value being checked is 2, and there is 1 1-bit in 2) But the output I DO get is:
Number of non-zero bits: ☐
Any help or advice would be very much appreciated!! I'm still very new to LC3 assembly...