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 JMPand convert those into binary opcodes. Each assembly instruction has a corresponding bit binary opcode. For example, the binary opcode for ADD is for AND it's and for JMP it's
Task
Write an LCassembly language program that does the following:
Output a message to the screen that prompts the user to type in an LCassembly language instruction like ADDThe user ends their input by pressing EnterReturn
If the instruction typed by the user is a legal LCassembly language instruction, your program displays the corresponding bit opcode. For example, if the user types "ADD", the program would print out
If the instruction typed by the user is not a legal LCassembly language instruction for example,ADDDyour 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 EnterReturn
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 ReturnEnter 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 Ayou move to the A State. In the A State you check to see if the next character is either Nor DAnything else would be an error. If the next characer is an Nyou move to the AN State. In the AN State you check the next character. If it's a Dyou 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 BRnot thevariantsBRnBRzBRpBRnzBRzpBRnpBRnzp
Write your program in a text editor not a word processor!and save the file as you goEvery 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 Wordis that word processors put a bunch of nonASCII 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 x
; Prompt message
PROMPT STRINGZ "Enter LC instruction or QUIT to exit:
; Valid opcodes
VALIDADD FILL x ; ADD opcode:
VALIDAND FILL x ; AND opcode:
VALIDBR FILL x ; BR opcode:
VALIDJMP FILL xC ; JMP opcode:
VALIDQUIT STRINGZ "QUIT"
; Program Variables
INPUTBUFFER BLKW # ; Input storage
CURRENTSTATE FILL x ; Current state of the FSM
; Main Program
START
LEA R PROMPT ; Load prompt message
PUTS ; Display prompt
LEA R INPUTBUFFER ; Prepare input buffer
JSR GETUSERINPUT ; Get user input
; Check if input is QUIT
LEA R INPUTBUFFER ; Check user input
LEA R VALIDQUIT ; Compare to "QUIT"
JSR STRCMP
BRz ENDPROGRAM ; If QUIT, exit program
; Process input
LEA R INPUTBUFFER
JSR PROCESSINPUT
BR START ; Loop back for next input
; Subroutine: GETUSERINPUT
; Description: Reads user input and stores in INPUTBUFFER
GETUSERINPUT
; Implementation here
RET
; Subroutine: PROCESSINPUT
; Description: FSM to process input and match valid instructions
PROCESSINPUT
; Implementation here
RET
; Subroutine: STRCMP
; Description: Compares two strings
STRCMP
; Implementation here
RET
ENDPROGRAM
HALT
END
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
