0

I want to convert the user input from string to integer to do multiplication and division operations. I tried to move the value to 'al' register then subtract 48 to convert it to int 'mov al, userInput' 'sub al, 48' but still the same issue, also I could not push the value of 'al' register to the stack 'push al' 'call printf'. Please any help in that.

global main
extern printf

SECTION .data
    ;--> Variables for the divisibility program
    InputMessage db "Enter a number: ", 0xa, 0x0
    OutputMessage db "Your value is : %d", 0xa, 0x0

SECTION .bss
    userInput resb 10


SECTION .text

main:
    global main
extern printf

SECTION .data
    ;--> Variables for timetable program
    msg db "    ", 0x0
    msge db "%d ", 0x0
    endl db 0xa, 0x0
    row dd 1
    col dd 1

    ;--> Variables for the divisibility program
    InputMessage db "Enter a number: ", 0xa, 0x0
    OutputMessage db "Your value is : %d", 0xa, 0x0

SECTION .bss
    userInput resb 10


SECTION .text

main:
    push InputMessage
    call printf
    pop ebx
    ;Reading user input
    mov eax, 3
    mov ebx, 1
    mov ecx, userInput
    mov edx, 10
    int 0x80

    ;userInput++
    mov eax, [userInput]
    inc eax
    push eax
    call printf

    ;exit
    mov eax, 1
    int 0x80

  • That only works for single digits. You should only load 1 byte and use `%hhd` format. PS: As a rule of thumb, do not mix raw system calls and C library functions. If you are allowed to use C library just invoke `scanf` to make your life easier, especially if the assignment is about division not user input handling. – Jester Dec 15 '21 at 23:28
  • (By "that" I mean subtracting 48, which you should definitely do.) – Jester Dec 15 '21 at 23:35
  • Hello @Jester thank you very much for your answer it was really helpful. I used scanf and it was easy to read input and convert it to int. – Bf Anas Dec 17 '21 at 08:41

0 Answers0