2 ; Programme qui lit une chaîne de caractère (et l'affiche deux fois)
6 CALL STRI ; STRI(buffer,size);
9 STRO buffer,d ; print(buffer + '\n' + buffer);
11 buffer: .BLOCK 20 ; Buffer for the string
12 size: .EQUATE 20 ; Size of the buffer
14 ; STRI: lit une ligne dans un tampon et place '\x00' à la fin
15 ; In: A=Adresse du tampon
16 ; X=Taille du tampon en octet
17 ; Out: A=Adresse du tampon (inchangé)
18 ; X=Nombre de caractères lu (ou offset du '\x00')
19 ; Err: Avorte si le tampon n'est pas assez grand pour
20 ; stocker la ligne et le '\0' final
21 STRI: STA striPtr,d ; sauve A;
23 STX striPtr2,d ; striPtr2 = A+X;
24 LDX striPtr,d ; X = striPtr;
25 striLoop:CPX striPtr2,d ; while(true) {
26 BRGE striErr ; if(X>=striPtr2) throws new Error();
27 CHARI 0,x ; *X = getChar();
33 BREQ striFin ; if(*X=='\n' || *X=='\x00') break;
35 BR striLoop ; } // fin boucle infinie
37 STBYTEA 0,x ; *X='\x00';
38 SUBX striPtr,d ; X = X-striPtr
39 LDBYTEA striPtr,d ; restaure A;
41 striErr: STRO striEMsg,d
43 striEMsg:.ASCII "STRI erreur: débordement de capacité\n\x00"
44 striPtr: .BLOCK 2 ; #2d adresse de début du tampon
45 striPtr2:.BLOCK 2 ; #2d adresse de fin de tampon (à ne pas écrire)