121 lines
3.7 KiB
Text
121 lines
3.7 KiB
Text
|
|
/* ARM assembly Raspberry PI */
|
||
|
|
/* program preend.s */
|
||
|
|
/* REMARK 1 : this program use routines in a include file
|
||
|
|
see task Include a file language arm assembly
|
||
|
|
for the routine affichageMess conversion10
|
||
|
|
see at end of this program the instruction include */
|
||
|
|
|
||
|
|
/*******************************************/
|
||
|
|
/* Constantes */
|
||
|
|
/*******************************************/
|
||
|
|
.include "../constantes.inc"
|
||
|
|
.equ NBCARLIBEL, 45
|
||
|
|
.equ BUFFERSIZE, 100
|
||
|
|
/*******************************************/
|
||
|
|
/* Macros */
|
||
|
|
/*******************************************/
|
||
|
|
//.include "../../ficmacros32.inc" @ for developer debugging
|
||
|
|
|
||
|
|
/*******************************************/
|
||
|
|
/* Initialized data */
|
||
|
|
/*******************************************/
|
||
|
|
.data
|
||
|
|
szMessDebutPgm: .asciz "Program 32 bits start. \n"
|
||
|
|
szCarriageReturn: .asciz "\n"
|
||
|
|
szMessFinOK: .asciz "Program normal end. \n"
|
||
|
|
szMessString: .asciz "British Museum.\n"
|
||
|
|
szStringStart: .asciz "The rosetta stone is at "
|
||
|
|
szMessErrSize: .asciz "Buffer error size too small.\n"
|
||
|
|
|
||
|
|
/*******************************************/
|
||
|
|
/* UnInitialized data */
|
||
|
|
/*******************************************/
|
||
|
|
.bss
|
||
|
|
sBuffer: .skip BUFFERSIZE
|
||
|
|
.align 4
|
||
|
|
|
||
|
|
/*******************************************/
|
||
|
|
/* code section */
|
||
|
|
/*******************************************/
|
||
|
|
.text
|
||
|
|
.global main
|
||
|
|
main:
|
||
|
|
ldr r0,iAdrszMessDebutPgm
|
||
|
|
bl affichageMess
|
||
|
|
|
||
|
|
ldr r0,iAdrszMessString
|
||
|
|
ldr r1,iAdrszStringStart
|
||
|
|
ldr r2,iAdrsBuffer
|
||
|
|
mov r3,#BUFFERSIZE
|
||
|
|
bl prepend // preend string1 to string2
|
||
|
|
cmp r0,#-1
|
||
|
|
beq 100f
|
||
|
|
ldr r0,iAdrszMessString
|
||
|
|
bl affichageMess
|
||
|
|
|
||
|
|
ldr r0,iAdrsBuffer
|
||
|
|
bl affichageMess
|
||
|
|
|
||
|
|
ldr r0,iAdrszMessFinOK
|
||
|
|
bl affichageMess
|
||
|
|
|
||
|
|
100: @ standard end of the program
|
||
|
|
mov r0, #0 @ return code
|
||
|
|
mov r7, #EXIT @ request to exit program
|
||
|
|
svc 0 @ perform system call
|
||
|
|
iAdrszMessDebutPgm: .int szMessDebutPgm
|
||
|
|
iAdrszMessFinOK: .int szMessFinOK
|
||
|
|
iAdrszCarriageReturn: .int szCarriageReturn
|
||
|
|
iAdrszMessString: .int szMessString
|
||
|
|
iAdrszStringStart: .int szStringStart
|
||
|
|
iAdrsBuffer: .int sBuffer
|
||
|
|
|
||
|
|
/**************************************************/
|
||
|
|
/* preend two strings */
|
||
|
|
/**************************************************/
|
||
|
|
/* r0 contains the address of the string1 */
|
||
|
|
/* r1 contains the address of the string2 */
|
||
|
|
/* r2 contains buffer */
|
||
|
|
/* r3 contains buffer size */
|
||
|
|
prepend:
|
||
|
|
push {r4-r6,fp,lr}
|
||
|
|
mov r4,#0 // counter byte string 2
|
||
|
|
mov r5,#0 // result byte counter
|
||
|
|
1: // copy string 2 in result area
|
||
|
|
ldrb r6,[r1,r4]
|
||
|
|
cmp r6,#0
|
||
|
|
beq 2f
|
||
|
|
strb r6,[r2,r5]
|
||
|
|
add r4,r4,#1 // increment indice
|
||
|
|
add r5,r5,#1 // increment indice
|
||
|
|
cmp r5,r3
|
||
|
|
bge 99f // error size
|
||
|
|
|
||
|
|
b 1b // and loop
|
||
|
|
2:
|
||
|
|
mov r4,#0 // counter byte string1
|
||
|
|
3:
|
||
|
|
ldrb r6,[r0,r4]
|
||
|
|
strb r6,[r2,r5]
|
||
|
|
cmp r6,#0
|
||
|
|
beq 4f
|
||
|
|
add r4,r4,#1 // increment indice
|
||
|
|
add r5,r5,#1 // increment indice
|
||
|
|
cmp r5,r3
|
||
|
|
bge 99f // error size
|
||
|
|
b 3b // and loop
|
||
|
|
4:
|
||
|
|
mov r0,r5
|
||
|
|
b 100f
|
||
|
|
99:
|
||
|
|
ldr r0,iAdrszMessErrSize
|
||
|
|
bl affichageMess
|
||
|
|
mov r0,#-1 // error
|
||
|
|
100:
|
||
|
|
pop {r4-r6,fp,pc}
|
||
|
|
iAdrszMessErrSize: .int szMessErrSize
|
||
|
|
/***************************************************/
|
||
|
|
/* ROUTINES INCLUDE */
|
||
|
|
/***************************************************/
|
||
|
|
.include "../affichage.inc"
|