0

I am rather new to assembly and am trying to perform arithmetic on a user defined integer consisting of one to three digits. I understand how single digits can be entered, converted from strings to integers, and manipulated, however, the process breaks down with multi-digit numbers.

section .text
    global _start
_start:
    ; Get user input
    mov edx, 5
    mov ecx, num
    mov ebx, 0
    mov eax, 3
    int 0x80
    
    mov eax, [num]

    ; HOW DO I CONVERT THE NUMBER IN THE EAX REIGSTER TO AN INTEGER I CAN MANIPULATE BELOW
    
    ; Check if 1 + num == 101 (arithmetic test)
    add eax, 1
    cmp eax, 101
    je print
    jmp exit

    print:
        mov edx, len
        mov ecx, one_hundo
        mov ebx, 1
        mov eax, 4
        int 0x80

    exit:
        mov eax, 1
        mov ebx, 0
        int 0x80

section .bss
    num resb 5

section .data
    one_hundo db 'You entered 100!',0xa
    len equ $ - one_hundo

As seen in the code above I get user input. If the user enters the number 100 I will add one to the number and if the result is equal to 101 I will print some text. I was wondering how I could convert the number in the eax register to an integer I can manipulate. I couldn't find any solutions on stackoverflow that would work in my code.

Liam
  • 1
  • It's arithmetic. For instance, start by zeroing a register. Every time you see another digit, multiply the register by 10 and add the digit you just saw (after subtracting `0`). – Nate Eldredge Apr 28 '22 at 06:29
  • @NateEldredge: My canonical answer on [NASM Assembly convert input to integer?](https://stackoverflow.com/a/49548057) explains the algorithm, and has a working loop that stops on the first non-digit. – Peter Cordes Apr 28 '22 at 13:15

0 Answers0