Saisir une chaîne de caractères en LC-3

Fermé
delfre56 Messages postés 340 Date d'inscription mardi 3 juillet 2012 Statut Membre Dernière intervention 23 février 2018 - 1 déc. 2015 à 15:14
Bonjour,
Pour un exercice de l'université (je suis en licence 1 info), on doit faire un petit programme à la con pour saisir une chaine de caractères au clavier en LC-3 et la sauver en mémoire. Voilà ce que j'ai fait :

;
; LireNom
; Author : Gaetan Geffroy
; Role : Subroutine
; Writes "Entrez votre nom" in console
; Read a string from the keyboard
;

.ORIG x3100

LireNom
ST R1, CCR1 ;Save register 1
ST R2, CCR2 ;Save register 2
LEA R2,ADRESS ;Initialise adress of the beginig of the string to read in R2
LEA R0,PROMPT ;Load the adress of the string to write in R0
PUTS ;"Entrez votre nom"

READ GETC
OUT
LD R1,CR ;R1 = -CR ASCII Code
ADD R1,R0,R1 ;Test if the user pressed the key "Enter"
BRz END
AND R3,R3,#0
ADD R3,R3,R0 ;Put the char value in R3
AND R0,R0,#0
ADD R0,R0,R2 ;Initialise R0 with the adress where it writes the char
STR R3,R0,#0 ;Save the caracter the the adress pointed by R0
ADD R2,R2,1
BRnzp READ

END LD R0,NULL ;Set the NULL ASCII code in R0
STR R0,R2,#0
LD R1,CCR1
LD R2,CCR2
HALT

PROMPT .STRINGZ "Entrez votre nom : " ;String to print in console
CCR1 .FILL x0100 ;Saving adress for R1
CCR2 .FILL x0101 ;Saving adress for R2
ADRESS .FILL x0200 ;Adress where to begin to write the string
CR .FILL xFFF3 ;2scomplement of the CR ASCII code
NULL .FILL x0000 ;ASCII code of the NULL char

.END

Le programme ne sort jamais de la boucle, il continue a lire des caractères à l'infini alors qu'il devrait arrêter quand j'appuie sur Entrée ! Si quelqu'un a déjà utilisé le LC-3, je suis preneur, ça fait trois heures que je m'arrache les cheveux dessus !