Trying Write Lc 3 Program Count Number Occurrences Char User Inputs String Hard Coded Part Q11076155

I am trying to write a LC-3 program that will count the numberof occurrences of a char that the user inputs in a string that ishard coded. The part that I am having trouble on is testing if thetwo characters equal each other, and I am also having troublemoving the next character in the string to test it.

;Program to count occurrences of a char in a string

.ORIG x3000

LD R3, POSASC ;Loads R3 with #48LD R4, NEGASCLD R1, word ;R1 = wordADD R6, R6, #5 ;Length of wordGETC ;Gets the charOUT ;Prints the charADD R2, R2, R0 ;Stores the char in R2;ADD R2, R2, R4 ;To asciiAND R0, R0, #0 ;set R0 back to 0LOOP AND R5, R2, R1 ;check if char is equalADD R1, R1, #1 ;increment to next char in wordADD R6, R6, #-1 BRnp LOOPADD R0, R0, R5 ;Set R0 to # of occurrencesOUT ;Print # of occurrencesHALTPOSASC .FILL x0030 ;#48word .STRINGZ “hello” ;word to count occurrences of a charNEGASC .FILL xFFD0 ;#-48.END

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *