Question: . ORIG x 3 0 0 0 ; Constants for BR instruction BR _ OPCODE . FILL x 0 0 0 0 BR _ MASK
ORIG x ; Constants for BR instruction BROPCODE FILL x BRMASK FILL xE ; Constants for other instructions ADDOPCODE FILL x ANDOPCODE FILL x JMPOPCODE FILL x JSROPCODE FILL x LDOPCODE FILL x LDIOPCODE FILL x LDROPCODE FILL x LEAOPCODE FILL x NOTOPCODE FILL x RETOPCODE FILL x RTIOPCODE FILL x STOPCODE FILL x STIOPCODE FILL x STROPCODE FILL x TRAPOPCODE FILL x ; Buffer for user input BUFFER BLKW ; States STARTSTATE FILL ASTATE FILL ANSTATE FILL ANDSTATE FILL ; Entry point MAIN ST R SAVER ; Save R LEA R PROMPT ; Print prompt message TRAP x ; TRAP to print string LEA R BUFFER ; Load address of the buffer LEA R BUFFER ; Load address of the buffer ADD R R # ; Initialize length counter to INPUTLOOP GETC ; Read a character OUT ; Echo the character ADD R R # ; Increment length counter STR R R # ; Store the character in the buffer ADD R R # ; Move to the next position ; Check for EnterReturn key LD R R # ADD R R # BRz PROCESSINPUT BR INPUTLOOP PROCESSINPUT LEA R BUFFER ; Load address of the buffer TRAP x ; TRAP to print a new line LEA R BUFFER ; Load address of the buffer ADD R R # ; Load address of the second character LD R R # ; Load the first character ADD R R # ; Convert to uppercase ; State machine AND R R #xFFE ; Mask the first five bits BRz ERRORSTATE ; If the first character is not alphabetic, go to error state ; Transition to the appropriate state based on the first character ADD R R # ; Calculate the offset to transition to the correct state ADD R R R BR R ASTATE ADD R R # ; Convert to lowercase ADD R R # ; Calculate the offset to the next state ADD R R R BR R ANSTATE ADD R R # ; Convert to lowercase ADD R R # ; Calculate the offset to the next state ADD R R R BR R ANDSTATE ADD R R # ADD R R # LDR R R # ; Load the opcode based on the state ADD R R R LEA R RESULT ; Load address of the result message TRAP x ; TRAP to print string BR STARTSTATE ; Go back to the start state ERRORSTATE LEA R ERRORMSG ; Load address of the error message TRAP x ; TRAP to print string STARTSTATE BR MAIN ; Go back to the main loop ; Data Section PROMPT STRINGZ "Enter an LC instruction: SAVERBLKW RESULT STRINGZ "The opcode is: ERRORMSG STRINGZ "Error: Invalid instruction! Please enter a valid LC instruction." 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
