C++ Sentinel Controlled Loop



In a sentinel-controlled loop, the prompts requesting data entry should explicitly remind the user of the sentinel value. After the loop terminates, the if. Else statement at lines 6980 executes. The condition at line 69 determines whether any grades were input. Instead you should nest your loops. The loop with the sentinel should be the outer loop, and the loop that validates and re-prompts the user should be the inner loop. Here is an example.

Hi,
I am having trouble writing a sentinel controlled loop in LC-3 assembly language. I know that you must store the sentinel somewhere in memory and that when the sentinel is detected, then the loop is done. However, how do you actually write this in LC-3 code.

Lets say I have the following example where I want to get user input of integers until the user enters a '#' character. How would I write the sent controlled loop for this. I have the following:

/
.ORIG x3000

LD R1, PTR
LD R6, SENT

LEA R0, PROMPT
PUTS

FOR_LOOP_1
TRAP x20
STR R0,R1,#0

ADD R1,R1,#1
BR TEST ;; how do you write the TEST loop. I know what i have is wrong

Sentinel Controlled Loop Example

TEST
LDR R3,R0,#0
AND R3,R3,#0
ADD R4,R3,R6

BR FOR_LOOP_1

Sentinel


HALT


SENT .FILL #35 ;;dec representation of '#'
PROMPT .STRINGZ 'ENTER NUMBERS, # WHEN YOU WANT TO STOP'

PTR .FILL x4000

.END
/

PLEASE HELP ME. THANKS

Sentinel Controlled Loop In C

  • 2 Contributors
  • forum2 Replies
  • 1,066 Views
  • 1 Month Discussion Span
  • commentLatest PostLatest Postby herpderp

Counter Controlled While Loop

Im struggling with this also.. I have a feeling that it is going to have something to do with converting the ascii code of your sentinal into some form of number then negating it with the NOT function and then if your test char ADDed to your sentinal equals 0, that would be your conditional.