LC3Tools ✡ Assignment3 Lavet udfra 1).asm BRnp IS PRIME ; Save the original value of R1 Handle the case when the input is 0 ; Increment the counter ; Check for divisibility by counter + counter ; Divide the input by (counter + counter) ; If the remainder is not 0, the number is prime 2 1 .ORIG x3000 isPrime 3 ST R1, SAVE_R1 4 5 AND R1, R1, #0 BRZ ZERO_CASE ; Clear R1 (to use as a counter) 6 LOOP 7 ADD R1, R1, #1 8 ADD R1, R1, #1 9 DIV RØ, R1 10 11 12 IS_PRIME 13 14 #1 ; 15 16 NOT PRIME 17 18 BRnzp DONE 19 ZERO_CASE 20 #0 21 DONE BRZ NOT PRIME AND RO, RO, #0 ADD RO, RO, BRnzp DONE AND RO, RO, #0 AND RO, RO, LD R1, SAVE_R1 RET SAVE_R1 .BLKW 1 22 23 24 25 .END 26 ; If the remainder is 0, the number is not prime ; Clear RO Set RØ to 1 (prime) ; Branch to DONE ; Clear RO (not prime) ; Branch to DONE ; Clear RO (0 is not prime) ; Restore the original value of R1 ; Return from the function ; Storage for saving R1

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Can someone help me draw a flow-diagram of this code in LC3 assembly language. 

Would appreciate it. 

 

.ORIG x3000

isPrime
    ST R1, SAVE_R1  ; Save the original value of R1
    AND R1, R1, #0  ; Clear R1 (to use as a counter)
    BRz ZERO_CASE   ; Handle the case when the input is 0

LOOP
    ADD R1, R1, #1  ; Increment the counter
    ADD R1, R1, #1  ; Check for divisibility by counter + counter
    DIV R0, R1      ; Divide the input by (counter + counter)
    BRnp IS_PRIME   ; If the remainder is not 0, the number is prime
    BRz NOT_PRIME   ; If the remainder is 0, the number is not prime

IS_PRIME
    AND R0, R0, #0  ; Clear R0
    ADD R0, R0, #1  ; Set R0 to 1 (prime)
    BRnzp DONE      ; Branch to DONE

NOT_PRIME
    AND R0, R0, #0  ; Clear R0 (not prime)
    BRnzp DONE      ; Branch to DONE

ZERO_CASE
    AND R0, R0, #0  ; Clear R0 (0 is not prime)

DONE
    LD R1, SAVE_R1  ; Restore the original value of R1
    RET             ; Return from the function

SAVE_R1 .BLKW 1     ; Storage for saving R1

.END

LC3Tools ✡
Assignment3 Lavet udfra 1).asm
BRnp IS PRIME
; Save the original value of R1
Handle the case when the input is 0
; Increment the counter
; Check for divisibility by counter + counter
; Divide the input by (counter + counter)
; If the remainder is not 0, the number is prime
2
1 .ORIG x3000
isPrime
3
ST R1, SAVE_R1
4
5
AND R1, R1, #0
BRZ ZERO_CASE
;
Clear R1 (to use as a counter)
6 LOOP
7
ADD R1, R1,
#1
8
ADD R1, R1,
#1
9
DIV RØ, R1
10
11
12
IS_PRIME
13
14
#1
;
15
16 NOT PRIME
17
18
BRnzp DONE
19
ZERO_CASE
20
#0
21 DONE
BRZ NOT PRIME
AND RO, RO, #0
ADD RO, RO,
BRnzp DONE
AND RO, RO, #0
AND RO, RO,
LD R1, SAVE_R1
RET
SAVE_R1 .BLKW 1
22
23
24
25
.END
26
;
If the remainder is 0, the number is not prime
; Clear RO
Set RØ to 1 (prime)
; Branch to DONE
; Clear RO (not prime)
; Branch to DONE
; Clear RO (0 is not prime)
; Restore the original value of R1
; Return from the function
; Storage for saving R1
Transcribed Image Text:LC3Tools ✡ Assignment3 Lavet udfra 1).asm BRnp IS PRIME ; Save the original value of R1 Handle the case when the input is 0 ; Increment the counter ; Check for divisibility by counter + counter ; Divide the input by (counter + counter) ; If the remainder is not 0, the number is prime 2 1 .ORIG x3000 isPrime 3 ST R1, SAVE_R1 4 5 AND R1, R1, #0 BRZ ZERO_CASE ; Clear R1 (to use as a counter) 6 LOOP 7 ADD R1, R1, #1 8 ADD R1, R1, #1 9 DIV RØ, R1 10 11 12 IS_PRIME 13 14 #1 ; 15 16 NOT PRIME 17 18 BRnzp DONE 19 ZERO_CASE 20 #0 21 DONE BRZ NOT PRIME AND RO, RO, #0 ADD RO, RO, BRnzp DONE AND RO, RO, #0 AND RO, RO, LD R1, SAVE_R1 RET SAVE_R1 .BLKW 1 22 23 24 25 .END 26 ; If the remainder is 0, the number is not prime ; Clear RO Set RØ to 1 (prime) ; Branch to DONE ; Clear RO (not prime) ; Branch to DONE ; Clear RO (0 is not prime) ; Restore the original value of R1 ; Return from the function ; Storage for saving R1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 1 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY