/* ARM assembly Raspberry PI */ /* program tasksearchRasp.s */ /* access RosettaCode.org and data extract */ /* use openssl for access to port 443 */ /* test openssl : package libssl-dev */ /* 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 EXIT, 1 .equ TAILLEBUFFER, 500 .equ SSL_OP_NO_SSLv3, 0x02000000 .equ SSL_OP_NO_COMPRESSION, 0x00020000 .equ SSL_MODE_AUTO_RETRY, 0x00000004 .equ SSL_CTRL_MODE, 33 .equ BIO_C_SET_CONNECT, 100 .equ BIO_C_DO_STATE_MACHINE, 101 .equ BIO_C_SET_SSL, 109 .equ BIO_C_GET_SSL, 110 .equ LGBUFFERREQ, 512001 .equ LGBUFFER2, 128001 /*********************************/ /* Initialized data */ /*********************************/ .data szMessDebutPgm: .asciz "Program 32 bits start \n" szRetourLigne: .asciz "\n" szMessFinOK: .asciz "Program end OK. \n" szMessErreur: .asciz "Erreur !!!" //szMessExtractArea: .asciz "Extraction = " szMessConnectOK: .asciz "Connexion site OK.\n" szMessInitOK: .asciz "Initialisation SSL OK.\n" szMessReqOK: .asciz "Send requete OK.\n" szNomSite1: .asciz "www.rosettacode.org:443" @ host name and port szLibStart: .asciz "" @ search string szLibsearch1: .asciz " loop add r0,#1 ldrb r2,[r0] cmp r2,#'c' bne 2b @ no -> loop b 100f @ yes -> list end 10: add r0,r5,#4 @ search if end of pgm task list ldrb r2,[r0] cmp r2,#'/' bne 1b add r0,#1 ldrb r2,[r0] cmp r2,#'c' bne 1b b 100f @ list pgm end 99: ldr r0,iAdrszMessErreur1 @ error bl affichageMess mov r0, #-1 @ error return code b 100f 100: pop {r1-r6,pc} @ restaur registers iAdrsBufferreq11: .int sBufferreq1 iAdrszLibStart: .int szLibStart iAdrszLibsearch1: .int szLibsearch1 iAdrszLibsearch2: .int szLibsearch2 iAdrszTaskName: .int szTaskName iAdrszTaskNamePgm: .int szTaskNamePgm iAdrszExtractArea: .int szExtractArea iAdrszExtractArea1: .int szExtractArea1 iAdrszRetourLigne: .int szRetourLigne iAdrszMessErreur1: .int szMessErreur /*********************************************************/ /* Text Extraction behind text key */ /*********************************************************/ /* r0 buffer address */ /* r1 key text to search */ /* r2 number occurences to key text */ /* r3 offset */ /* r4 result address */ extChaine: push {r2-r8,lr} @ save registers mov r5,r0 @ save buffer address mov r6,r1 @ save key text @ compute text length mov r7,#0 1: @ loop ldrb r0,[r5,r7] @ load a byte cmp r0,#0 @ end ? addne r7,#1 @ no -> loop bne 1b add r7,r5 @ compute text end mov r8,#0 2: @ compute length text key ldrb r0,[r6,r8] cmp r0,#0 addne r8,#1 bne 2b 3: @ loop to search nième(r2) key text mov r0,r5 mov r1,r6 bl rechercheSousChaine cmp r0,#0 blt 100f subs r2,#1 addgt r5,r0 addgt r5,r8 bgt 3b add r0,r5 @ add address text to index add r3,r0 @ add offset sub r3,#1 @ and add length key text add r3,r8 cmp r3,r7 @ > at text end movge r0,#-1 @ yes -> error bge 100f mov r0,#0 4: @ character loop copy ldrb r2,[r3,r0] strb r2,[r4,r0] cmp r2,#0 @ text end ? moveq r0,#0 @ return zero beq 100f cmp r2,#'"' @ text end ? beq 5f cmp r0,#48 @ extraction length beq 5f add r0,#1 b 4b @ and loop 5: mov r2,#0 @ store final zéro strb r2,[r4,r0] add r0,#1 add r0,r3 @ r0 return the last position of extraction @ it is possible o search another text 100: pop {r2-r8,pc} @ restaur registers /******************************************************************/ /* search substring in string */ /******************************************************************/ /* r0 contains address string */ /* r1 contains address substring */ /* r0 return start index substring or -1 if not find */ rechercheSousChaine: push {r1-r6,lr} @ save registers mov r2,#0 @ index position string mov r3,#0 @ index position substring mov r6,#-1 @ search index ldrb r4,[r1,r3] @ load first byte substring cmp r4,#0 @ zero final ? moveq r0,#-1 @ error beq 100f 1: ldrb r5,[r0,r2] @ load string byte cmp r5,#0 @ zero final ? moveq r0,#-1 @ yes -> not find beq 100f cmp r5,r4 @ compare character two strings beq 2f mov r6,#-1 @ not equal - > raz index mov r3,#0 @ and raz byte counter ldrb r4,[r1,r3] @ and load byte add r2,#1 @ and increment byte counter b 1b @ and loop 2: @ characters equal cmp r6,#-1 @ first character equal ? moveq r6,r2 @ yes -> start index in r6 add r3,#1 @ increment substring counter ldrb r4,[r1,r3] @ and load next byte cmp r4,#0 @ zero final ? beq 3f @ yes -> search end add r2,#1 @ else increment string index b 1b @ and loop 3: mov r0,r6 @ return start index substring in the string 100: pop {r1-r6,pc} @ restaur registres /***************************************************/ /* ROUTINES INCLUDE */ /***************************************************/ .include "../affichage.inc"