0

我已经尝试编写代码好几个小时了。我的算法是逐字符读取字符串,减法#$30,这意味着'0'并将其保存在一个地址中。保存另一个用0填充的随机地址。然后直到字符串的末尾,将随机地址的内容乘以10,然后通过减法将用于转换int的地址的内容相加#$30。我真的很累,很难实现我的算法。顺便说一句,我不知道这是否可能,但我想我不能使用 default multiplier EMUL,因为它使用并写入 Y 和 D 寄存器。

一些伪:

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           
4

0 回答 0