0

This are the instructions that I have:

global _start


_start:
    mov ecx, 0x12
    mov ebx, 0x2

label:
    add ebx, ebx
    dec ecx
    cmp ecx, 0
    jg label
    mov eax, 1
    int 0x80

I am new to assembly and am essentially trying to multiply two numbers. I am compiling the above code with nasm -f elf32 ./ex1.asm && ld -m elf_i386, running the output binary ./a.out and checking the return value with echo $? right after I run ./a.out. I get 0 as a return value however I am expecting to get what is stored in ebx as a return value. Furthermore, when I replace 0x12 and 0x2 with 0x2, 0x3, respectively, I get the return value of 12. I tried increasing this numbers and until certain point I get some unrelated value as a return value and then I only get 0.

Furthermore, when I replace 0x12 and 0x2 with 0x2, 0x3, respectively, I get the return value of 12. I tried increasing this numbers and until certain point I get some unrelated value as a return value and then I only get 0.

David Wohlferd
  • 7,110
  • 2
  • 29
  • 56

1 Answers1

1

The return code from a process is only 8 bits. Your code will result in 2**18, which is 0x40000, so the low-order byte is 0.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30