Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10 DIM oc$(1000), of%(1000), v%(1000)
- 20 OPEN "I", 1, "data08.txt"
- 30 FOR i = 0 TO 1000
- 40 IF EOF(1) GOTO 70
- 50 oc$(i) = INPUT$(3, # 1): INPUT #1, of%(i)
- 60 NEXT i
- 70 ic = i
- 80 PRINT "Part 1"
- 90 GOSUB 500
- 100 PRINT "Final value of accumulator:"; r
- 200 PRINT "Part 2"
- 210 FOR i = 0 TO ic - 1
- 220 IF oc$(i) = "acc" THEN GOTO 280
- 230 PRINT "Changing instruction"; i; "...";
- 240 IF oc$(i) = "nop" THEN oc$(i) = "jmp": GOSUB 500: oc$(i) = "nop"
- 250 IF oc$(i) = "jmp" THEN oc$(i) = "nop": GOSUB 500: oc$(i) = "jmp"
- 260 IF c = 1 GOTO 290
- 270 PRINT "Loop detected."
- 280 NEXT i
- 290 PRINT "Program finished!"
- 300 PRINT "Final accumulator value:"; r
- 310 END
- 500 FOR j = 0 TO 1000: v%(j) = 0: NEXT j
- 510 ip = 0: acc = 0
- 520 IF v%(ip) THEN c = 0: r = acc: RETURN
- 530 IF ip >= ic THEN c = 1: r = acc: RETURN
- 540 v%(ip) = -1
- 550 IF oc$(ip) = "jmp" THEN ip = ip + of%(ip) - 1
- 560 IF oc$(ip) = "acc" THEN acc = acc + of%(ip)
- 570 ip = ip + 1
- 580 GOTO 520
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement