How to resolve the algorithm Split a character string based on change of character step by step in the AArch64 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Split a character string based on change of character step by step in the AArch64 Assembly programming language

Table of Contents

Problem Statement

Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below).

Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas.

For instance, the string: should be split and show:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Split a character string based on change of character step by step in the AArch64 Assembly programming language

Source code in the aarch64 programming language

/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program splitcar64.s   */

/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
szCarriageReturn:   .asciz "\n"
szString1:          .asciz "gHHH5YY++///\\"
/*   IMPORTANT REMARK for compiler as 
The way to get special characters into a string is to escape these characters: precede them
with a backslash ‘\’ character. For example ‘\\’ represents one backslash: the first \ is
an escape which tells as to interpret the second character literally as a backslash (which
prevents as from recognizing the second \ as an escape character).
*/
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
sBuffer:               .skip  100
 
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                              // entry of program 
 
    ldr x0,qAdrszString1           // input string address
    ldr x1,qAdrsBuffer             // output buffer address
    bl split 
 
    ldr x0,qAdrsBuffer
    bl affichageMess               // display message
    ldr x0,qAdrszCarriageReturn
    bl affichageMess 
 
 
100:                               // standard end of the program 
    mov x0,0                       // return code
    mov x8,EXIT                    // request to exit program
    svc 0                          // perform the system call
 
qAdrszString1:            .quad szString1
qAdrszCarriageReturn:     .quad szCarriageReturn
qAdrsBuffer:              .quad sBuffer
 
/******************************************************************/
/*     generate value                                  */ 
/******************************************************************/
/* x0 contains the address of input string  */
/* x1 contains the address of output buffer  */
 
split:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x4,0                       // indice loop input string
    mov x5,0                       // indice buffer
    ldrb w2,[x0,x4]                // read first char in reg x2
    cbz x2,4f                       // if null -> end
    strb w2,[x1,x5]                // store char in buffer
    add x5,x5,1                    // increment location buffer
1:
    ldrb w3,[x0,x4]                //read char[x4] in reg x3
    cbz x3,4f                      // if null  end
    cmp x2,x3                      // compare two characters
    bne 2f
    strb w3,[x1,x5]                // = -> store char in buffer   
    b 3f                           // loop
2:
    mov x2,','                    // else store comma in buffer
    strb w2,[x1,x5]                // store char in buffer
    add x5,x5,1
    mov x2,' '                    // and store space in buffer
    strb w2,[x1,x5]
    add x5,x5,1
    strb w3,[x1,x5]               // and store input char in buffer
    mov x2,x3                     // and maj x2 with new char
3:
    add x5,x5,1                   // increment indices
    add x4,x4,1
    b 1b                          // and loop
4:
    strb w3,[x1,x5]               // store zero final in buffer
100:
    ldp x1,lr,[sp],16             // restaur  2 registers
    ret                           // return to address lr x30
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

  

You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Forth programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the Rascal programming language
You may also check:How to resolve the algorithm Variables step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm DNS query step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Y combinator step by step in the Lambdatalk programming language