.file "primes.c" .section .rodata .align 2 .LC0: .ascii "Prime Number Calculator\000" .align 2 .LC1: .ascii "=======================\000" .global __modsi3 .align 2 .LC2: .ascii "%d\000" .align 2 .LC3: .ascii " is a prime number.\000" .align 2 .LC4: .ascii "Do you want to continue (Y or N)? \000" .align 2 .LC5: .ascii "\012Quitting the Prime Number Calculator\000" .text .align 2 .global main .type main, %function main: @ args = 0, pretend = 0, frame = 28 @ frame_needed = 1, uses_anonymous_args = 0 mov ip, sp stmfd sp!, {fp, ip, lr, pc} sub fp, ip, #4 sub sp, sp, #28 mov r3, #99328 @compiler split z into 99328+672 add r3, r3, #672 @uses shifted values to fit IMM field mov r6, r3 @@ move value into z mov r3, #1 @manually move 1 to a register for True? str r3, [fp, #-20] @fp-20 is value of true mov r3, #0 str r3, [fp, #-16] @fp-16 is value of false mov r8, #1 @@ initialize repeat with true b .L19 @.L19 starts the while(repeat) loop .L3: mov r0, #10 bl putchar ldr r0, .L20 bl puts ldr r0, .L20+4 bl puts mov r5, #2 @@ y, initialized to 2 b .L4 .L5: mov r7, #1 @@ prime, initialized to true mov r4, #2 @@ x, initialized to 2 b .L18 .L7: @@ convert load-stores to Register moves mov r0, r5 @set up r0 with y mov r1, r4 @set up r1 with x (for y mod x) bl __modsi3 @Modulo function, need to link mov r3, r0 @r0 contains results of (y mod x) cmp r3, #0 bne .L8 mov r7, #0 @@ prime gets false b .L6 .L8: @x++ add r4, r4, #1 @@ x++ (removed load and store) .L6: .L18: @@ remove loads mov r3, r5, lsr #31 @@ y add r3, r3, r2 mov r3, r3, asr #1 mov r2, r3 cmp r2, r4 @@ Compare r2 with x blt .L10 ldr r3, [fp, #-20] cmp r7, r3 @@ Compare prime with true beq .L7 .L10: @@ remove loads cmp r7, #1 @@ compare prime with true bne .L12 ldr r0, .L20+8 mov r1, r5 @@ setup y in r1 for printf bl printf ldr r0, .L20+12 bl puts .L12: add r5, r5, #1 @@ increment y .L4: @@ remove loads cmp r5, r6 @@ compare y with z ble .L5 mov r0, #10 bl putchar ldr r0, .L20+16 bl printf ldr r3, [fp, #-16] str r3, [fp, #-24] ldr r3, [fp, #-24] cmp r3, #0 bne .L2 ldr r0, .L20+20 bl puts .L2: .L19: cmp r8, #0 @ compare repeat and false, remove load bne .L3 mov r3, #0 mov r0, r3 sub sp, fp, #12 ldmfd sp, {fp, sp, pc} .L21: .align 2 .L20: .word .LC0 .word .LC1 .word .LC2 .word .LC3 .word .LC4 .word .LC5 .size main, .-main .ident "GCC: (GNU) 4.1.0"