0

I am trying to make a program in x86 NASM that reads two integers from stdin and then does something with them (greatest common divisor, but thats not the question here). The question I have, is now that I have the two input integers, how do I go about turning them into actual integers to use as such? Here is the code I use to grab the strings of digits

SECTION .data

prompt: db      "Enter a positive integer: "
plen:   equ     $-prompt

SECTION .bss

inbuf:  resb 20
inbuf2: resb 20

    SECTION .text

    global  _start

    _start:

       ; Here I am grabbing the two integers to use in the function

      nop
      mov       eax, 4          ; write
      mov       ebx, 1          ; to standard output
      mov       ecx, prompt     ; the prompt string
      mov       edx, plen       ; of length plen
      int   80H             ; interrupt with the syscall

      mov       eax, 3          ; read
      mov       ebx, 0          ; from standard input
      mov       ecx, inbuf      ; into the input buffer
      mov       edx, 30     ; upto 30 bytes
      int   80H             ; interrupt with the syscall

      mov       eax, 4          ; write
      mov       ebx, 1          ; to standard output
      mov       ecx, prompt     ; the prompt string
      mov       edx, plen       ; of length plen
      int   80H             ; interrupt with the syscall

      mov       eax, 3          ; read
      mov       ebx, 0          ; from standard input
      mov       ecx, inbuf2     ; into the input buffer
      mov       edx, 30     ; upto 30 bytes
      int   80H             ; interrupt with the syscall
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
bock.steve
  • 221
  • 2
  • 12
  • 1
    To convert the character `'2'` to an integer 2, you subtract 0x30 (ascii value of the number zero): `0x32 - 0x30 = 2`. To convert the string "123" to an integer, you calculate `1*100 + 2*10 + 3`. – that other guy May 05 '17 at 22:23
  • For the lazy copypaster: http://stackoverflow.com/a/19312503/3512216 – rkhb May 06 '17 at 08:41
  • 1
    Possible duplicate of [NASM Assembly convert input to integer?](http://stackoverflow.com/questions/19309749/nasm-assembly-convert-input-to-integer) – David Hoelzer May 06 '17 at 16:39

0 Answers0