1

I'm a beginner in assembly language. I try to multiply two numbers.

section .data
a dw 1;
b dw 2;
global _start 

section .text
_start:
mov eax, [a];
mov ebx, [b];
movv:
mul ebx;
mull:

mov eax, 1;
mov ebx, 0;
int 80h;

I compile and run it with the following command: nasm -g -f elf pr1.s && ld -m elf_i386 pr1.o -o pr1 && gdb ./pr1
When I in gdb view the register eax value I get 131073 and ebx 65538
Why I get this values instead of 1 and 2?

Edit about duplicate

In duplicated question the author mostly asks about meaning of db, dw, dd operations, while in this question is being asked how to solve particular error. Nevertheless, duplicate question also useful for extended information about size of variables in assembly.

Alexander L
  • 41
  • 1
  • 6
  • 2
    `mov eax, [a]` loads 4 bytes, but `a`is only two bytes. Use `movzx eax, word [a]` instead. – prl Sep 22 '20 at 07:13
  • 4
    `a` and `b` are words, but you're doing doubleword reads. Either change `dw` to `dd`, or change `mov` to `movzx eax, word [a]`. – Michael Sep 22 '20 at 07:13

1 Answers1

1

In comments, Michael answered on my question, changing dw to dd solved the problem.

Alexander L
  • 41
  • 1
  • 6