270 lines
7.6 KiB
Text
270 lines
7.6 KiB
Text
/* ARM assembly AARCH64 Raspberry PI 3B */
|
|
/* program Comma quibbling */
|
|
|
|
/*******************************************/
|
|
/* Constantes */
|
|
/*******************************************/
|
|
/* for this file see task include a file in language AArch64 assembly*/
|
|
.include "../includeConstantesARM64.inc"
|
|
.equ BUFFERSIZE, 80
|
|
|
|
/*******************************************/
|
|
/* macros */
|
|
/*******************************************/
|
|
//.include "../../ficmacros64.inc" // for developper debugging
|
|
|
|
/*********************************/
|
|
/* Initialized data */
|
|
/*********************************/
|
|
.data
|
|
szMessDebutPgm: .asciz "Program 64 bits start. \n"
|
|
szCarriageReturn: .asciz "\n"
|
|
szMessFinOK: .asciz "Program normal end. \n"
|
|
szMessStringError: .asciz "Error : Empty string !!!\n"
|
|
szMessBufferError: .asciz "Error : Buffer too small !!\n"
|
|
szMessEndStringError: .asciz "Error: End string, not ].\n"
|
|
szMessWordErr: .asciz "Error word empty.\n"
|
|
szAnd: .asciz " and "
|
|
szString1: .asciz "[]"
|
|
szString2: .asciz "[\"ABC\"]"
|
|
szString3: .asciz "[\"ABC\",\"DEF\"]"
|
|
szString4: .asciz "[\"ABC\",\"DEF\",\"G\",\"H\"]"
|
|
szString5: .asciz "[\"AB"
|
|
szString6: .asciz "[\"ABC\",,\"DEF\"]"
|
|
|
|
.align 4
|
|
/*********************************/
|
|
/* UnInitialized data */
|
|
/*********************************/
|
|
.bss
|
|
sBuffer: .skip BUFFERSIZE
|
|
.align 4
|
|
|
|
/*********************************/
|
|
/* code section */
|
|
/*********************************/
|
|
.text
|
|
.global main
|
|
main:
|
|
ldr x0,qAdrszMessDebutPgm
|
|
bl affichageMess // start message
|
|
|
|
ldr x0,qAdrszString1
|
|
bl execTest
|
|
ldr x0,qAdrszString2
|
|
bl execTest
|
|
ldr x0,qAdrszString3
|
|
bl execTest
|
|
ldr x0,qAdrszString4
|
|
bl execTest
|
|
ldr x0,qAdrszString5
|
|
bl execTest
|
|
ldr x0,qAdrszString6
|
|
bl execTest
|
|
|
|
ldr x0,qAdrszMessFinOK
|
|
bl affichageMess
|
|
|
|
100:
|
|
mov x8,EXIT
|
|
svc #0 // system call
|
|
qAdrszMessDebutPgm: .quad szMessDebutPgm
|
|
qAdrszMessFinOK: .quad szMessFinOK
|
|
qAdrszCarriageReturn: .quad szCarriageReturn
|
|
qAdrszString1: .quad szString1
|
|
qAdrszString2: .quad szString2
|
|
qAdrszString3: .quad szString3
|
|
qAdrszString4: .quad szString4
|
|
qAdrszString5: .quad szString5
|
|
qAdrszString6: .quad szString6
|
|
qAdrsBuffer: .quad sBuffer
|
|
/******************************************************************/
|
|
/* test execution */
|
|
/******************************************************************/
|
|
/* x0 contains string address */
|
|
execTest:
|
|
stp x1,lr,[sp,-16]!
|
|
stp x2,x4,[sp,-16]!
|
|
mov x4,x0
|
|
bl affichageMess // display start string
|
|
ldr x0,qAdrszCarriageReturn
|
|
bl affichageMess
|
|
mov x0,x4 // string address
|
|
ldr x1,qAdrsBuffer // buffer address
|
|
mov x2,#BUFFERSIZE
|
|
bl stringAnalyse
|
|
cmp x0,#-1 // error ?
|
|
beq 100f
|
|
ldr x0,qAdrsBuffer // buffer display
|
|
bl affichageMess
|
|
ldr x0,qAdrszCarriageReturn
|
|
bl affichageMess
|
|
100:
|
|
ldp x2,x4,[sp],16
|
|
ldp x1,lr,[sp],16
|
|
ret
|
|
/******************************************************************/
|
|
/* string conversion */
|
|
/******************************************************************/
|
|
/* x0 contains string address */
|
|
/* x1 contains buffer address */
|
|
/* x2 contains buffer length */
|
|
stringAnalyse:
|
|
stp x1,lr,[sp,-16]!
|
|
stp x2,x3,[sp,-16]!
|
|
stp x4,x5,[sp,-16]!
|
|
stp x6,x7,[sp,-16]!
|
|
stp x8,x9,[sp,-16]!
|
|
sub sp,sp,#BUFFERSIZE // reserve area on stack for temporary buffer
|
|
mov fp,sp
|
|
mov x7,#0 // indice write buffer
|
|
mov x5,#0 // word counter
|
|
mov x6,#0 // word char count
|
|
|
|
mov x3,#0 // indice string
|
|
1:
|
|
ldrb w4,[x0,x3] // load string char
|
|
cmp x4,#0 // end ?
|
|
bne 2f
|
|
cmp x3,#0 // first char ?
|
|
beq 97f // error empty string
|
|
b 97f // end string error
|
|
2:
|
|
cmp x4,#'[' // first symbol ?
|
|
bne 3f
|
|
mov x4,#'{' // write symbol
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
add x3,x3,#1 // increment indice
|
|
b 1b // and loop
|
|
3:
|
|
cmp x4,#']' // end symbol ?
|
|
bne 8f
|
|
cmp x5,#0 // no word ?
|
|
beq 7f
|
|
cmp x5,#1
|
|
beq 5f // last and first word
|
|
|
|
mov x9,#0
|
|
ldr x12,qAdrszAnd
|
|
4: // loop write and
|
|
ldrb w4,[x12,x9]
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
add x9,x9,#1
|
|
cmp x9,#5
|
|
blt 4b
|
|
|
|
5: // last word
|
|
mov x9,#0
|
|
6: // loop write temporary buffer
|
|
ldrb w4,[fp,x9]
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
add x9,x9,#1
|
|
cmp x9,x6
|
|
blt 6b
|
|
mov x6,#0 // raz indice temporary buffer
|
|
7:
|
|
mov x4,#'}'
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
mov x4,#0
|
|
strb w4,[x1,x7] // final 0
|
|
b 100f
|
|
8:
|
|
cmp x4,#',' // comma ?
|
|
beq 9f
|
|
cmp x6,#0
|
|
cinc x5,x5,eq // new word increment word counter
|
|
//addeq x5,x5,#1 // new word increment word counter
|
|
strb w4,[fp,x6] // store char in temporary buffer
|
|
add x6,x6,#1
|
|
add x3,x3,#1
|
|
b 1b // loop
|
|
|
|
9:
|
|
cmp x6,#0 // word empty ?
|
|
beq 96f
|
|
cmp x5,#1 // first word ?
|
|
bne 11f
|
|
// first word, write only the word
|
|
mov x9,#0
|
|
10: // loop write temporary buffer
|
|
ldrb w4,[fp,x9]
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
add x9,x9,#1
|
|
cmp x9,x6
|
|
blt 10b
|
|
mov x6,#0 // raz indice temporary buffer
|
|
add x3,x3,#1
|
|
b 1b // loop
|
|
11:
|
|
mov x4,#','
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
|
|
mov x9,#0
|
|
12: // loop write temporary buffer
|
|
ldrb w4,[fp,x9]
|
|
strb w4,[x1,x7]
|
|
add x7,x7,#1
|
|
cmp x7,x2
|
|
bge 99f // buffer error
|
|
add x9,x9,#1
|
|
cmp x9,x6
|
|
blt 12b
|
|
mov x6,#0 // raz indice temporary buffer
|
|
add x3,x3,#1
|
|
b 1b // loop
|
|
|
|
96: // errors messages
|
|
ldr x0,qAdrszMessWordErr
|
|
bl affichageMess
|
|
mov x0,#-1
|
|
b 100f
|
|
97:
|
|
ldr x0,qAdrszMessEndStringErr
|
|
bl affichageMess
|
|
mov x0,#-1
|
|
b 100f
|
|
98:
|
|
ldr x0,qAdrszMessStringError
|
|
bl affichageMess
|
|
mov x0,#-1
|
|
b 100f
|
|
99:
|
|
ldr x0,qAdrszMessBufferError
|
|
bl affichageMess
|
|
mov x0,#-1
|
|
100:
|
|
add sp,sp,#BUFFERSIZE
|
|
ldp x8,x9,[sp],16
|
|
ldp x6,x7,[sp],16
|
|
ldp x4,x5,[sp],16
|
|
ldp x2,x3,[sp],16
|
|
ldp x1,lr,[sp],16
|
|
ret
|
|
qAdrszMessStringError: .quad szMessStringError
|
|
qAdrszMessBufferError: .quad szMessBufferError
|
|
qAdrszMessEndStringErr: .quad szMessEndStringError
|
|
qAdrszMessWordErr: .quad szMessWordErr
|
|
qAdrszAnd: .quad szAnd
|
|
/***************************************************/
|
|
/* ROUTINES INCLUDE */
|
|
/***************************************************/
|
|
/* for this file see task include a file in language AArch64 assembly*/
|
|
.include "../includeARM64.inc"
|