Closed GoogleCodeExporter closed 9 years ago
This bug may have been a side-effect of the hold-down-return bug we had
previously. It worked in the
example we had used that caused the issue previously after fixing that bug, and
it appears to work correctly.
Example text is:
; Multiplication de deux petits nombres entiers par la methode des paysans
russes (le produit < 2^15 = 32K)
; lhb (150310)
;Exemple d'exécution:
; entrée: 9 -11
; sortie: 9 * -11= -99
; etiquetage des entrees sur la pile
; pp (main)
n: .EQUATE 2 ; local variable #2d (multiplicande)
m: .EQUATE 0 ; local variable #2d (multiplicateur)
; fonction (mult)
A: .EQUATE 8 ; local variable #2d (sauvegarde A)
X: .EQUATE 6 ; local variable #2d (sauvegarde X)
mult2: .EQUATE 4 ; local variable #2d (puissances binaires de n)
div2: .EQUATE 2 ; local variable #2d (facteurs binaires de m)
result: .EQUATE 0 ; local variable #2d (resultat cumule)
main: SUBSP 4,i ; allocate #m #n
DECI nombre1,d ; lire n
DECO nombre1,d ; ecrire n
LDA nombre1,d
STA n,s ; empiler comme multiplicande
STRO texte1,d
DECI nombre2,d ; line m
DECO nombre2,d ; ecrire m
LDA nombre2,d
STA m,s ; empiler comme multiplicateur
STRO texte2,d
CALL mult
LDA m,s ; le resultat remplace le multiplicande
STA produit,d
ADDSP 4,i ; deallocate #n #m
DECO produit,d
STOP
mult: SUBSP 10,i ; allocate #A #X #mult2 #div2 #result
STA A,s ; sauvegarde A
STX X,s ; sauvegarde X
LDX 12,s ; multiplicateur
BRGE debut ; if(multiplicateur < 0){
NEGX
STX 12,s ; |multiplicateur|
LDA 14,s ; multiplicande
NEGA
STA 14,s ; -multiplicande
debut: LDA 14,s ; }
STA mult2,s ; mult2 = n;
LDA 12,s
STA div2,s ; div2 = m;
LDA 0,i
STA result,s ; result = 0;
LDA mult2,s
LDX div2,s
repete: CPX 0,i ; while(div2 != 0){
BREQ fini
ASRX ; div2 /= 2;
BRC ajoute ; if(div2 % 2 != 0) Ajoute
fois2: ASLA ; mult2 *= 2;
BR repete ; }
ajoute: STA mult2,s
ADDA result,s
STA result,s ; result += mult2;
LDA mult2,s
BR fois2
fini: LDA result,s
STA 12,s
LDX X,s ; restaure X
LDA A,s ; restaure A
ADDSP 10,i ; deallocate #result #div2 #mult2 #X #A
RET0
;---------DONNEES
STATIQUES----------------------------------------------------------
----
; NOTE seul le pp utilise l'espace statique
nombre1: .BLOCK 2 ; global variable #2d
nombre2: .BLOCK 2 ; global variable #2d
produit: .BLOCK 2 ; global variable #2d
texte1: .ASCII " * "
.BYTE 0
texte2: .ASCII " = "
.BYTE 0
.END
Example input is: 2 3
Expected output is 2 * 3 = 6
Original comment by chris.dimpfl
on 4 May 2010 at 10:17
Original issue reported on code.google.com by
chris.dimpfl
on 30 Mar 2010 at 11:37