RosettaCodeData/Task/Strip-comments-from-a-string/AArch64-Assembly/strip-comments-from-a-strin...

100 lines
2.8 KiB
Plaintext

/* ARM assembly AARCH64 Raspberry PI 3B */
/* program Strip comments from a string */
/*******************************************/
/* Constantes */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* 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"
szString1: .asciz "apples, pears # and bananas"
szString2: .asciz "apples, pears ; and bananas"
.align 4
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
.align 4
/*********************************/
/* code section */
/*********************************/
.text
.global main
main:
ldr x0,qAdrszMessDebutPgm
bl affichageMess // start message
ldr x0,qAdrszString1
mov x1,#'#'
bl suppComment
ldr x0,qAdrszString1
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString2
mov x1,#';'
bl suppComment
ldr x0,qAdrszString1
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
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
/******************************************************************/
/* strip comment string */
/******************************************************************/
/* x0 contains string address */
/* x1 contains comment markers */
/* x0 returns length of string */
suppComment:
stp x1,lr,[sp,-16]!
stp x2,x3,[sp,-16]!
mov x2,#0 // indice string
1:
ldrb w3,[x0,x2]
cmp x3,#0 // end string
csel x0,x2,x0,eq
beq 100f
cmp x3,x1
cinc x2,x2,ne
bne 1b
mov x3,#0
strb w3,[x0,x2]
mov x0,x2
100:
ldp x2,x3,[sp],16
ldp x1,lr,[sp],16
ret
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeARM64.inc"