Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- CONTROL: .word 0x10000
- DATA: .word 0x10008
- A: .word 17; N value
- B: .word 2 ; i value
- .text
- ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; load memory-mapped IO addresses
- ld r20,CONTROL(r0) ; load CONTROL address
- ld r21,DATA(r0) ; load DATA address
- ld r10,A(r0) ; loads r10 as 17, n value
- ld r11,B(r0) ; loads r11 as 2, i value
- daddi r2,r0,0
- daddi r3,r0,1
- ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- isPrime:
- beq r11,r10,prime ; if r11 hits r10,it is prime then jump to prime, e.g: 17 = 17
- ; N i
- ddiv r2,r10,r11 ;divide r10 by r11, put value into r2 17 / 2 = r2
- dmul r2,r2,r11 ;multiply r2 by r11, put value into r2 r2 * 2 = r2
- ; if r2 = r10 , number is prime
- beq r2,r10,done ; if r2 hits r10, stop if a number before r11=r10 can divide in once successfully then end program
- daddi r11,r11,1 ; i++ / B++
- j isPrime
- prime:
- dadd r1,r0,r11
- sd r1,0(r21) ; set DATA to output value
- daddi r1,r0,2
- sd r1,0(r20) ; write CONTROL
- done:
- halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement