ps5pr8 - ps5pr8(Problem Set 5 Problem 8 Determine if a number is prime 00 read r1 get from user and store it in r1 01 setn r3 2 set r3 = 2 02 div r2

ps5pr8 - ps5pr8(Problem Set 5 Problem 8 Determine if a...

This preview shows page 1 out of 1 page.

# # ps5pr8.txt (Problem Set 5, Problem 8) # # Determine if a number is prime # 00 read r1 # get # from user and store it in r1 01 setn r3 2 # set r3 = 2 02 div r2 r1 r3 # set r2 = r1 // r3 03 call r14 11 # Copy the next address into r14 and then jump to mem. addr. 11 04 write r3 # print the value of r3 05 sub r6 r3 r1 # set r6 = r3 - r1 06 setn r7 1 # set r7 = 1 07 jeqz r6 09 # if r6 == 0, jump to line 09 08 setn r7 0 # set r7 = 0 09 write r7 # print the value of r7 10 halt 11 mod r4 r1 r3 # set r4 = r1 % r3 12 jeqz r4 18 # if r4 == 0, jump to line 18 13 addn r3 1 # add 1 to r3 14 sub r5 r3 r2 # set r5 = r3 - r2 15 jgtz r5 17 # if r5 > 0, jump to line 17 16 jumpn 11 # jump to line 11 17 copy r3 r1 # set r3 = r1 18 jumpr r14 # jump to address in r14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture