Condition flags aren't updated when reading keyboard characters
rpendleton opened this issue · 0 comments
While trying to reproduce the issue for #43, I ran into another issue related to the traps. It turns out the traps aren't updating condition flags, which can result in some odd behavior.
I think this is best illustrated using the following program:
.orig x3000
read_character:
in
loop:
brnzp loop
print_message:
lea r0, msg
puts
halt
msg: .STRINGZ "hello world"
.end
Given that brnzp is essentially an unconditional jmp, this program should read a single character and then hang in the loop. You can confirm this is the case with the official lc3sim program, as well as my implementation that uses the lc3os.obj file. However, the article's implementation results in some pretty interesting behavior:
$ ./lc3 input.obj
Enter a character: fhello worldHALT
Notice how even though it should be stuck in the loop, it actually continues to print_message and executes the rest of the program? (And if the halt isn't included, the program actually restarts and goes back to read_character, which I assume is due to the PC register overflowing. I haven't checked to see how the real lc3sim handles this though.)