I'm fairly new to ASM. I'm running ARCH linux 64 bit and use the following commands to compiule and everything runs smoothly:
nasm -f elf32 -o file.o file.asm
ld -s -m elf_i386 -o file file.o
I am taking user input (as a decimal) and I simply want to double it. However, when I use:
add eax, eax
I get no ouput. I then tried:
add eax, 1
Which should add 1 to eax. However, this adds 1 to the memory address. I have 10 bytes reserved in my .bss section.
When I type "1234" it ouputs "234" (shifted +1 byte) as opposed to "1235"
.bss section:
i: resd
j: resd 10
Full statement:
mov eax, 3 ;syscall
mov ebx, 2 ;syscall
mov ecx, i ;input variable
mov edx, 10 ;length of 'i'
int 0x80 ;kernel call
mov eax, i ;moving i into eax
add eax, 0x1 ;adding 1 to eax
mov [j], eax ;moving eax into j
What you are operating on is a string representation of the number.
You probably need to:
So something like (untested code ahead):
Page 22 of this document contains a NASM implementation of the atoi function.