0

I have been trying to write the code for hours. My algorithm is that read the string char-by-char, subtract #$30, which means '0' and hold it in a address. Hold another random address in which is filled by 0. Then until end of the string, multiply by 10 content of the random address and add content of the address which is used to convert int by subtracting #$30. I'm really exhausted and hard to implement my algorithm. By the way, I don't know whether it is possible but, I think I can't use default multiplier EMUL, because it uses and writes onto Y and D registers.

Some pseudos:

num = num*10 + conv(next digit).
var * 10:
res = var
res << 1 (shift left)
res << 1
res = res + var
res << 1

Now res equals var*10

My stucked code:

MYSTR   FCC   "1337"
Entry:

             LDX   #MYSTR
             CLRA
             STAA  $1900    ; random address
loop:
             LDAA  1, x+    ; pointer to string
             CMPA  #0       ; check end of string
             BEQ   halt     ; if end of string end the program
             BRA   atoi     ; num in accumulator A is converted to int
             ;BRA halt

atoi:
             STAA  $1300
             LDAB  $1300
             SUBB  #$30
             ;----- number - '0' converts to int
             JSR   mult 
             BRA   loop

mult:
             CLRB
             STAB  $1350
             MOVB  $1350, $1351 ; copy content of 1350(var) to 1351(res)
             ASL   $1351
             ASL   $1351
             LDAA  $1351
             ADDA  $1350   ; res += var;
             ASLA  ; res << 1

             RTS

halt:
            SWI           
  • For one thing you seem to be multiplying the `next digit` by 10, not the `num`. – Jester Mar 13 '16 at 22:17
  • you have to multiply the current value by 10, and then add the next digit; e.g. value computed so far = 13, next char = '3' : 13 + '3' = 13*10 + 3 = 133 – Tommylee2k Mar 14 '16 at 08:25

0 Answers0