Question: The issue I am having is that it keeps repeating itself when you run the program indefinitely. Also how do I make it an ASM

The issue I am having is that it keeps repeating itself when you run the program indefinitely.
Also how do I make it an ASM file.
Thank you!
Please submit your code as a .asm file (a .asm file is just a text file with the extension ".asm").
One of the things an assembler has to do is take assembly language instructions (like ADD, AND, and JMP)and convert those into binary opcodes. Each assembly instruction has a corresponding 4-bit binary opcode. For example, the binary opcode for ADD is 0001,for AND it's 0101,and for JMP it's 1100.
Task
Write an LC-3assembly language program that does the following:
Output a message to the screen that prompts the user to type in an LC-3assembly language instruction (like ADD).The user ends their input by pressing Enter/Return.
If the instruction typed by the user is a legal LC-3assembly language instruction, your program displays the corresponding 4-bit opcode. For example, if the user types "ADD", the program would print out "0001"
.If the instruction typed by the user is not a legal LC-3assembly language instruction (for example,"ADDD"),your program displays an appropriate error message.
After displaying the output, your program loops back to the top, reinitializes anything that needs to be reinitialized, and goes again.
Your program will exit when the user types the string "QUIT" and presses Enter/Return.
IMPORTANT NOTES
Your program must treat input as case insensitive, meaning that the user can type their input in any combination of upper and lower case. For example, "ADD", "add",and "AdD" would all be legal instructions.
As the user types an instruction, your program should echo each typed character to the monitor so they can see what they're typing.
You can process characters as the user enters them or you can store them away and process them after the user hits the Return or Enter key. If you process characters as they are entered, you still have to wait until after the user hits Return/Enter before you give an error response, even if you already know it's not a valid instruction.
The algorithm you use for processing the text has to use a state machine. If the user types an 'A',you move to the A State. In the A State you check to see if the next character is either 'N'or 'D'.Anything else would be an error. If the next characer is an 'N'you move to the AN State. In the AN State you check the next character. If it's a 'D'you move to the AND State, otherwise it's an error. In the AND State, the next character has to be the CR or LF character, otherwise it's an error. Etc., etc. Rinse and repeat for all valid instructions.
For the BR instruction, you only need to handle "BR",not thevariants("BRn","BRz","BRp","BRnz","BRzp","BRnp","BRnzp").
Write your program in a text editor (not a word processor!)and save the file as you go.Every time you need to assemble and load the file into the Simulator you can just drag the file onto the assembler. The reason you shouldn't use a word processor (like Word)is that word processors put a bunch of non-ASCII junk into a document file. Plus they do things like smart quotes, which look like regular quotes but have a different underlying value, so the assembler doesn't interpret it correctly.
Here is my code
; Program Start
.ORIG x3000
; Prompt message
PROMPT .STRINGZ "Enter LC-3 instruction (or QUIT to exit): "
; Valid opcodes
VALID_ADD .FILL x1 ; ADD opcode: 0001
VALID_AND .FILL x5 ; AND opcode: 0101
VALID_BR .FILL x0 ; BR opcode: 0000
VALID_JMP .FILL xC ; JMP opcode: 1100
VALID_QUIT .STRINGZ "QUIT"
; Program Variables
INPUT_BUFFER .BLKW #10 ; Input storage
CURRENT_STATE .FILL x0 ; Current state of the FSM
; Main Program
START
LEA R0, PROMPT ; Load prompt message
PUTS ; Display prompt
LEA R1, INPUT_BUFFER ; Prepare input buffer
JSR GET_USER_INPUT ; Get user input
; Check if input is QUIT
LEA R0, INPUT_BUFFER ; Check user input
LEA R1, VALID_QUIT ; Compare to "QUIT"
JSR STRCMP
BRz END_PROGRAM ; If QUIT, exit program
; Process input
LEA R0, INPUT_BUFFER
JSR PROCESS_INPUT
BR START ; Loop back for next input
; Subroutine: GET_USER_INPUT
; Description: Reads user input and stores in INPUT_BUFFER
GET_USER_INPUT
; Implementation here
RET
; Subroutine: PROCESS_INPUT
; Description: FSM to process input and match valid instructions
PROCESS_INPUT
; Implementation here
RET
; Subroutine: STRCMP
; Description: Compares two strings
STRCMP
; Implementation here
RET
END_PROGRAM
HALT
.END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!