this post was submitted on 05 Mar 2024
4 points (100.0% liked)

Programming

3347 readers
1 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 2 years ago
MODERATORS
 

I created this function for converting a string taken from standard input to an integer:

str2int:
    mov rax, 0

    L2:
        cmp byte [input + r10], 0
        je done2

        add al, [input + r10]
        sub rax, '0'
        imul rax, 10

        inc r10
        jmp L2

    done2:
    ret

but when i use it, it adds an extra 0 at the end of the number (example: a 1 gets turned into a 10, a 30 into a 300 and so), what is the problem with it?

you are viewing a single comment's thread
view the rest of the comments
[–] BenM2023 1 points 9 months ago

Even I, who haven't looked at asy for very many years, and when I did I was no asy programmer, can see the problem.

I don't want to do homework so not posting the answer but my top tip for discovering the bug is to step through your code on paper...