Write an LC-3 program (starting at memory location 0x3000) that checks if a stri
ID: 3825402 • Letter: W
Question
Write an LC-3 program (starting at memory location 0x3000) that checks if a string is the reverse of another string. The end of the string is denoted by '#' Your program should take both the strings as inputs from the keyboard. If the two strings are reverse of each other, you need to print "Y" to the screen, else you need to print "N" to the screen. In particular, your code should do the following things: a) Read an input character from the keyboard. b) Test if the character is '#'. If the character is 'H', you successfully read the first string S1. c) Start reading input character from the keyboard again. d) Test if the character is If the character is you successfully read the second string S2. e) Compare the two input strings S1 and S2. f) If S2 is the reverse of S1, display "Y" else display "N".Explanation / Answer
.ORIG 0x3000 LEA R2,STRING LEA R3,GNIRTS LD R4,MINUS1 NOT R6,R1 ADD R6,R6,1 SCAN LDR R5,R2,0 BRZ COPY ADD R2,R2,1 BRNZP SCAN COPY ADD R2,R2,R4 ADD R5,R2,R6 BRN COPIED LDR R5,R2,0 STR R5,R3,0 ADD R3,R3,1 BRNZP COPY COPIED AND R5,R5,0 STR R5,R3,0 LEA R1,GNIRTS PUTS HALT MINUS1 .FILL STRING .STRINGZ GNIRTS .BLKW .END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.