When I run my program, it is supposed to go through the rest of my code when I type anything but QUIT, but when I type anything, it just HALTS my program.
This question is the same project that I'm working on, but at a different stage-text
I have tried modifying my code as to the order it executes, but it doesn't help. I have gone through the debugger, but can't identify the exact problem.
Here is my code for this specfic loop, for reference:
; String compare function
STRING_COMPARE_QUIT AND R0, R0, #0 ; Initialize result to 0
; R1 points to 'QUIT', R2 to INPUT_BUFFER
; R3/R4 are characters from the strings
; R5 is a comparison flag, R6 for lowercase checking
; R6 is the lowercase mask
CASE_INSENSITIVE_COMPARE_QUIT
LEA R1, QUIT ; Point to the string "QUIT"
LD R2, INPUT_BUFFER ; Point to the input buffer
AND R5, R5, #0 ; Clear the comparison flag
CHECK_LOOP_QUIT
LDR R3, R1, #0 ; Load character from "QUIT"
LDR R4, R2, #0 ; Load character from input buffer
; Check if R3 is lowercase and convert it to uppercase if it is
LD R6, MASK ; Load the lowercase mask value into R6
AND R6, R3, R6 ; Mask off bits with R6 to check if it's a lowercase letter
BRz NOT_LOWERCASE_1_QUIT ; Zero flag means it's not a lowercase letter
ADD R3, R3, #0 ; Make sure condition codes are set based on R3
BRn NOT_LOWERCASE_1_QUIT ; Negative flag means it's not a lowercase letter (ASCII < 'a')
BRzp CASE_CHECK_R3_QUIT ; Zero or positive means we have a lowercase letter
NOT_LOWERCASE_1_QUIT
BRnzp SKIP_CONVERSION_1_QUIT ; Skip conversion if not lowercase
CASE_CHECK_R3_QUIT
LD R6, MASK ; Load the value 32 into R6 from memory
AND R6, R3, R6 ; Apply mask with R6 to check if R3's character is lowercase
BRz CONVERT_R3_QUIT ; If zero, convert this lowercase to uppercase
; This label is no longer needed since BRnzp is unconditional here and
; we don't have any instructions in between
SKIP_CONVERSION_1_QUIT ; This line should be removed eventually, unless you have more code to add here.
BRnzp NEXT_INSTRUCTION_QUIT ; Always jump to the next instructionstruction if no conversion needed
CONVERT_R3_QUIT
LD R6, TO_UPPERCASE ; Load the value 32 into R6
NOT R3, R3 ; Invert R3 to prepare for addition
ADD R3, R3, #1 ; Add 1 to complete 2's complement negation
ADD R3, R3, R6 ; Add R6 (which is 32) to complete the subtraction, effectively converting lowercase to uppercase
NEXT_INSTRUCTION_QUIT
; Check if R4 is lowercase and convert it to uppercase if it is
LD R6, MASK ;
AND R6, R4, R6 ; Mask off bits to check if it's a lowercase letter
BRz NOT_LOWERCASE_2_QUIT ; Zero flag means it's not a lowercase letter
ADD R4, R4, #0 ; Make sure condition codes are set based on R4
BRn NOT_LOWERCASE_2_QUIT ; Negative flag means it's not a lowercase letter (ASCII < 'a')
BRzp CASE_CHECK_R4 ; Zero or positive means we have a lowercase letter
NOT_LOWERCASE_2_QUIT
BRnzp SKIP_CONVERSION_2_QUIT ; Skip conversion if not lowercase
CASE_CHECK_R4_QUIT
LD R6, MASK
AND R6, R4, R6
BRz CONVERT_R4_QUIT
SKIP_CONVERSION_2_QUIT
BRnzp NEXT_INSTRUCTION_FOR_R4_QUIT
CONVERT_R4_QUIT
LD R6, TO_UPPERCASE
NOT R4, R4
ADD R3, R3, #1
ADD R4, R4, R6 ; Convert lowercase to uppercase by adding binary 0010000
; Continue on with the processing of R4
NEXT_INSTRUCTION_FOR_R4_QUIT
ADD R6, R3, #0 ; Update flags based on R3 value
BRz CHECK_QUIT_END ; If R3 is NULL, go check input buffer end
ADD R6, R4, #0 ; Update flags based on R4 value
BRz STRINGS_NOT_EQUAL_QUIT ; If R4 is NULL here, it's a mismatch
; No NULL is encountered, so compare the characters
CHAR_EQUAL_QUIT
ADD R1, R1, #1 ; Increment to the next character of "QUIT"
ADD R2, R2, #1 ; Increment to the next character of the input buffer
BRnzp CHECK_LOOP ; Continue the loop
CONTINUE_COMPARE_QUIT
ADD R1, R1, #1 ; Move to the next character in "QUIT"
ADD R2, R2, #1 ; Move to the next character in input buffer
BRnzp CHECK_LOOP_QUIT ; Loop back
CHECK_QUIT_END
ADD R6, R4, #0 ; Copy R4 to check if input also ends
BRz STRINGS_ARE_EQUAL_QUIT ; If R4 is NULL, both strings end here, thus are equal
BRnzp STRINGS_NOT_EQUAL_QUIT ; If R4 is not NULL, mismatch
STRINGS_NOT_EQUAL_QUIT
BRnzp STRING_COMPARE_QUIT_EXIT
STRINGS_ARE_EQUAL_QUIT
; Set flag for "equal", Input matches "QUIT" (case insensitive)
AND R5, R5, #0 ; Clear R5
ADD R5, R5, #1 ; Set R5 to indicate strings are equal
BRzp EXIT
STRING_COMPARE_QUIT_EXIT