
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Display a substring:

   starting from   n   characters in and of   m   length;
   starting from   n   characters in,   up to the end of the string;
   whole string minus the last character;
   starting from a known   character   within the string and of   m   length;
   starting from a known   substring   within the string and of   m   length.


If the program uses UTF-8 or UTF-16,   it must work on any valid Unicode code point,
whether in the   Basic Multilingual Plane   or above it.

The program must reference logical characters (code points),   not 8-bit code units for UTF-8 or 16-bit code units for UTF-16.

Programs for other encodings (such as 8-bit ASCII, or EUC-JP) are not required to handle all Unicode characters.




Other tasks related to string operations:

Metrics
 Array length
 String length
 Copy a string
 Empty string  (assignment)
Counting
 Word frequency
 Letter frequency
 Jewels and stones
 I before E except after C
 Bioinformatics/base count
 Count occurrences of a substring
 Count how many vowels and consonants occur in a string
Remove/replace
 XXXX redacted
 Conjugate a Latin verb
 Remove vowels from a string
 String interpolation (included)
 Strip block comments
 Strip comments from a string
 Strip a set of characters from a string
 Strip whitespace from a string -- top and tail
 Strip control codes and extended characters from a string
Anagrams/Derangements/shuffling
 Word wheel
 ABC problem
 Sattolo cycle
 Knuth shuffle
 Ordered words
 Superpermutation minimisation
 Textonyms (using a phone text pad)
 Anagrams
 Anagrams/Deranged anagrams
 Permutations/Derangements
Find/Search/Determine
 ABC words
 Odd words
 Word ladder
 Semordnilap
 Word search
 Wordiff  (game)
 String matching
 Tea cup rim text
 Alternade words
 Changeable words
 State name puzzle
 String comparison
 Unique characters
 Unique characters in each string
 Extract file extension
 Levenshtein distance
 Palindrome detection
 Common list elements
 Longest common suffix
 Longest common prefix
 Compare a list of strings 
 Longest common substring
 Find common directory path
 Words from neighbour ones
 Change e letters to i in words
 Non-continuous subsequences
 Longest common subsequence
 Longest palindromic substrings
 Longest increasing subsequence
 Words containing "the" substring
 Sum of the digits of n is substring of n
 Determine if a string is numeric
 Determine if a string is collapsible
 Determine if a string is squeezable
 Determine if a string has all unique characters
 Determine if a string has all the same characters
 Longest substrings without repeating characters
 Find words which contains all the vowels
 Find words which contains most consonants
 Find words which contains more than 3 vowels
 Find words which first and last three letters are equals
 Find words which odd letters are consonants and even letters are vowels or vice_versa
Formatting
 Substring
 Rep-string
 Word wrap
 String case
 Align columns
 Literals/String
 Repeat a string
 Brace expansion
 Brace expansion using ranges
 Reverse a string
 Phrase reversals
 Comma quibbling
 Special characters
 String concatenation
 Substring/Top and tail
 Commatizing numbers
 Reverse words in a string
 Suffixation of decimal numbers
 Long literals, with continuations 
 Numerical and alphabetical suffixes
 Abbreviations, easy
 Abbreviations, simple
 Abbreviations, automatic
Song lyrics/poems/Mad Libs/phrases
 Mad Libs
 Magic 8-ball
 99 Bottles of Beer
 The Name Game (a song)
 The Old lady swallowed a fly
 The Twelve Days of Christmas
Tokenize
 Text between
 Tokenize a string
 Word break problem
 Tokenize a string with escaping
 Split a character string based on change of character
Sequences
 Show ASCII table
 De Bruijn sequences
 Self-referential sequences
 Generate lower case ASCII alphabet




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program subString64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessString:            .asciz "Result : " 
szString1:               .asciz "abcdefghijklmnopqrstuvwxyz"
szStringStart:           .asciz "abcdefg"
szCarriageReturn:        .asciz "\n"
/*******************************************/ 
/* UnInitialized data                      */
/*******************************************/
.bss 
szSubString:             .skip 500             // buffer result
 
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main: 
 
    ldr x0,qAdrszString1                        // address input string
    ldr x1,qAdrszSubString                      // address output string
    mov x2,22                                   // location
    mov x3,4                                    // length
    bl subStringNbChar                          // starting from n characters in and of m length
    ldr x0,qAdrszMessString                     // display message
    bl affichageMess
    ldr x0,qAdrszSubString                      // display substring result
    bl affichageMess
    ldr x0,qAdrszCarriageReturn                 // display line return
    bl affichageMess
    //
    ldr x0,qAdrszString1
    ldr x1,qAdrszSubString
    mov x2,15                                   // location
    bl subStringEnd                             //starting from n characters in, up to the end of the string
    ldr x0,qAdrszMessString                     // display message
    bl affichageMess
    ldr x0,qAdrszSubString
    bl affichageMess
    ldr x0,qAdrszCarriageReturn                 // display line return
    bl affichageMess
    //
    ldr x0,qAdrszString1
    ldr x1,qAdrszSubString
    bl subStringMinus                           // whole string minus last character
    ldr x0,qAdrszMessString                     // display message
    bl affichageMess
    ldr x0,qAdrszSubString
    bl affichageMess
    ldr x0,qAdrszCarriageReturn                 // display line return
    bl affichageMess
    //
    ldr x0,qAdrszString1
    ldr x1,qAdrszSubString
    mov x2,'c'                                  // start character
    mov x3,5                                    // length
    bl subStringStChar                          //starting from a known character within the string and of m length
    cmp x0,-1                                   // error ?
    beq 2f
    ldr x0,qAdrszMessString                     // display message
    bl affichageMess
    ldr x0,qAdrszSubString
    bl affichageMess
    ldr x0,qAdrszCarriageReturn                 // display line return
    bl affichageMess
    //
2:
    ldr x0,qAdrszString1
    ldr x1,qAdrszSubString
    ldr x2,qAdrszStringStart                    // sub string to start
    mov x3,10                                   // length
    bl subStringStString                        // starting from a known substring within the string and of m length
    cmp x0,-1                                   // error ?
    beq 3f
    ldr x0,qAdrszMessString                     // display message
    bl affichageMess
    ldr x0,qAdrszSubString
    bl affichageMess
    ldr x0,qAdrszCarriageReturn                 // display line return
    bl affichageMess
3:
100:                                            // standard end of the program
    mov x0,0                                    // return code
    mov x8,EXIT                                 // request to exit program
    svc 0                                       // perform system call
qAdrszMessString:         .quad szMessString
qAdrszString1:            .quad szString1
qAdrszSubString:          .quad szSubString
qAdrszStringStart:        .quad szStringStart
qAdrszCarriageReturn:     .quad szCarriageReturn
/******************************************************************/
/*     sub strings  index start  number of characters             */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of the output string */
/* x2 contains the start index                  */
/* x3 contains numbers of characters to extract */
/* x0 returns number of characters or -1 if error */
subStringNbChar:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x14,#0                     // counter byte output string 
1:
    ldrb w15,[x0,x2]               // load byte string input
    cbz x15,2f                     // zero final ?
    strb w15,[x1,x14]              // store byte output string
    add x2,x2,1                    // increment counter
    add x14,x14,1
    cmp x14,x3                     // end ?
    blt 1b                         // no -> loop
2:
    strb wzr,[x1,x14]              // store final zero byte string 2
    mov x0,x14
100:
    ldp x1,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/******************************************************************/
/*     sub strings  index start at end of string             */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of the output string */
/* x2 contains the start index                  */
/* x0 returns number of characters or -1 if error */
subStringEnd:
    stp x2,lr,[sp,-16]!            // save  registers
    mov x14,0                      // counter byte output string 
1:
    ldrb w15,[x0,x2]               // load byte string 1
    cbz x15,2f                     // zero final ?
    strb w15,[x1,x14]
    add x2,x2,1
    add x14,x14,1
    b 1b                           // loop
2:
    strb wzr,[x1,x14]              // store final zero byte string 2
    mov x0,x14
100:
 
    ldp x2,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/******************************************************************/
/*      whole string minus last character                        */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of the output string */
/* x0 returns number of characters or -1 if error */
subStringMinus:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x12,0                      // counter byte input string
    mov x14,0                      // counter byte output string 
1:
    ldrb w15,[x0,x12]              // load byte string 
    cbz x15,2f                     // zero final ?
    strb w15,[x1,x14]
    add x12,x12,1
    add x14,x14,1
    b 1b                           //  loop
2:
    sub x14,x14,1
    strb wzr,[x1,x14]              // store final zero byte string 2
    mov x0,x14
100:
    ldp x1,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/******************************************************************/
/*   starting from a known character within the string and of m length  */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of the output string */
/* x2 contains the character    */
/* x3 contains the length
/* x0 returns number of characters or -1 if error */
subStringStChar:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x16,0                      // counter byte input string
    mov x14,0                      // counter byte output string 
1:
    ldrb w15,[x0,x16]              // load byte string 
    cbz x15,4f                     // zero final ?
    cmp x15,x2                     // character find ?
    beq 2f                         // yes
    add x16,x16,1                  // no -> increment indice
    b 1b                           //  loop
2:
    strb w15,[x1,x14]
    add x16,x16,1
    add x14,x14,1
    cmp x14,x3
    bge 3f
    ldrb w15,[x0,x16]              // load byte string 
    cbnz x15,2b                    // loop if no zero final
3:
    strb wzr,[x1,x14]              // store final zero byte string 2
    mov x0,x14
    b 100f
4:
    strb w15,[x1,x14]
    mov x0,#-1
100:
    ldp x1,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/******************************************************************/
/*   starting from a known substring within the string and of m length  */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of the output string */
/* x2 contains the address of string to start    */
/* x3 contains the length
/* x0 returns number of characters or -1 if error */
subStringStString:
    stp x1,lr,[sp,-16]!            // save  registers
    stp x20,x21,[sp,-16]!          // save  registers
    mov x20,x0                     // save address
    mov x21,x1                     // save address output string
    mov x1,x2
    bl searchSubString
    cmp x0,-1                      // not found ?
    beq 100f
    mov x16,x0                     // counter byte input string
    mov x14,0
1:
    ldrb w15,[x20,x16]             // load byte string 
    strb w15,[x21,x14]
    cmp x15,#0                     // zero final ?
    csel x0,x14,x0,eq
    beq 100f
    add x14,x14,1
    cmp x14,x3
    add x15,x16,1
    csel x16,x15,x16,lt
    blt 1b                         //  loop
    strb wzr,[x21,x14]
    mov x0,x14                     // return indice
100:
    ldp x20,x21,[sp],16              // restaur  2 registers
    ldp x1,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/******************************************************************/
/*   search a substring in the string                            */ 
/******************************************************************/
/* x0 contains the address of the input string */
/* x1 contains the address of substring */
/* x0 returns index of substring in string or -1 if not found */
searchSubString:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x12,0                      // counter byte input string
    mov x13,0                      // counter byte string 
    mov x16,-1                     // index found
    ldrb w14,[x1,x13]
1:
    ldrb w15,[x0,x12]              // load byte string 
    cbz x15,4f                     // zero final ?
    cmp x15,x14                    // compare character 
    beq 2f
    mov x16,-1                     // no equals - > raz index 
    mov x13,0                      // and raz counter byte
    add x12,x12,1                  // and increment counter byte
    b 1b                           // and loop
2:                                 // characters equals
    cmp x16,-1                     // first characters equals ?
    csel x16,x12,x16,eq
   // moveq x6,x2                  // yes -> index begin in x6
    add x13,x13,1                  // increment counter substring
    ldrb w14,[x1,x13]              // and load next byte
    cbz x14,3f                     // zero final ? yes -> end search
    add x12,x12,1                  // else increment counter string
    b 1b                           // and loop
3:
    mov x0,x16                     // return indice
    b 100f
4:
   mov x0,#-1                      // yes returns error
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"
 