RosettaCodeData/Task/Pi/ARM-Assembly/pi.arm

156 lines
4.1 KiB
Plaintext

/* ARM assembly Raspberry PI */
/* program calculPi.s Spigot algorithm */
/* conversion to Pascal */
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../constantes.inc"
.equ NBVAL, 3000
.equ LEN, 10 * NBVAL / 3 @ 10000
//.include "../ficmacros32.inc" @ for debugging developper
/************************************/
/* Initialized data */
/************************************/
.data
szCarriageReturn: .asciz "\n"
szMessStart: .asciz "Program 32 bits start.\n"
szVal9: .asciz "9"
szVal0: .asciz "0"
.align 2
/************************************/
/* UnInitialized data */
/************************************/
.bss
sZoneConv: .skip 24
ibuffer: .skip 4 * (LEN+1)
/************************************/
/* code section */
/************************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrszMessStart
bl affichageMess
ldr r12,iN
ldr r10,iLen
mov r1,#0
ldr r8,iAdribuffer
mov r2,#2
1: @ init start array loop
str r2,[r8,r1, lsl #2] @ store 2
add r1,#1
cmp r1,r10
blt 1b
mov r9,#0 @ nine
mov r7,#0 @ predigit
mov r6,#0 @ j
2: @ begin loop 1
mov r5,#0 @ q
sub r4,r10,#1 @ i
3: @ loop 2
ldr r0,[r8,r4, lsl #2] @ load value
mov r1,#10
mul r0,r1,r0 @ val * 10
mul r1,r5,r4 @ q *i
add r0,r1
lsl r1,r4,#1 @ divisor =i *2
sub r1,#1 @ - 1
bl division
str r3,[r8,r4, lsl #2] @ modulo 2i-1
mov r5,r2 @ q
subs r4,#1 @ decremente i
bgt 3b @ end loop 2
mov r0,r5
mov r1,#10
bl division
str r3,[r8,#4] @ poste 0 = q mod 10
mov r5,r2 @ q = q/10
cmp r5,#9
beq 7f
cmp r5,#10
beq 5f
mov r0,r7
bl afficherPredigit
mov r7,r5 @ predigit=q
cmp r9,#0 @ nine
beq 8f
mov r1,#1 @ else
4:
cmp r1,r9
bgt 41f
ldr r0,iAdrszVal9
bl affichageMess
add r1,#1
b 4b
41:
mov r9,#0 @ raz nine
b 8f
5: @ q = 10
add r0,r7,#1
bl afficherPredigit
mov r7,#0 @ predigit=0
mov r1,#1
6:
cmp r1,r9
bgt 61f
ldr r0,iAdrszVal0
bl affichageMess
add r1,#1
b 6b
61:
mov r9,#0 @ raz nine
b 8f
7:
add r9,#1
8:
add r6,#1
cmp r6,r12
ble 2b @ end loop 1 ?
mov r0,r7
bl afficherPredigit
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform the system call
iAdrsZoneConv: .int sZoneConv
iAdrszCarriageReturn: .int szCarriageReturn
iAdrszMessStart: .int szMessStart
iAdribuffer: .int ibuffer
iN: .int NBVAL
iLen: .int LEN
iAdrszVal9: .int szVal9
iAdrszVal0: .int szVal0
/******************************************************************/
/* Display predigit */
/******************************************************************/
/* r0 contains decimale */
afficherPredigit:
push {r4,lr} @ save registers
mov r4,r0
ldr r1,iAdrsZoneConv
bl conversion10 @ decimal conversion
mov r2,#0
strb r2,[r1,r0]
ldr r0,iAdrsZoneConv
bl affichageMess
100:
pop {r4,pc} @ restaur registers
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../affichage.inc"