I have been trying to write the code on HCS12 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.
My stucked code:
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
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
Last edited by a moderator: