Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to write a LC-3 program that will count the number of occurrences of a char that the user inputs in a string

I am trying to write a LC-3 program that will count the number of occurrences of a char that the user inputs in a string that is hard coded. The part that I am having trouble on is testing if the two characters equal each other, and I am also having trouble moving 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 #48 LD R4, NEGASC LD R1, word ;R1 = word ADD R6, R6, #5 ;Length of word GETC ;Gets the char OUT ;Prints the char ADD R2, R2, R0 ;Stores the char in R2 ;ADD R2, R2, R4 ;To ascii AND R0, R0, #0 ;set R0 back to 0 LOOP AND R5, R2, R1 ;check if char is equal ADD R1, R1, #1 ;increment to next char in word ADD R6, R6, #-1 BRnp LOOP ADD R0, R0, R5 ;Set R0 to # of occurrences OUT ;Print # of occurrences HALT POSASC .FILL x0030 ;#48 word .STRINGZ "hello" ;word to count occurrences of a char NEGASC .FILL xFFD0 ;#-48 .END 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago