T
T
Tolik2014-05-31 19:27:01
linux
Tolik, 2014-05-31 19:27:01

Assembler (linux x64 nasm) how to return the value obtained by subtracting from one variable to another?

Here is what I wrote:

section .bss

  num1 resb 2
  num2 resb 2

global _start

section .text
_start:

  mov [num1], dword 500
  mov [num2], dword 300

  sub [num1], dword num2
  
  mov ebx, num1

  mov eax, 1
  int 80h

But when I type echo $? then I see that the program returns 224, not 200 as I wanted. Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afiskon, 2014-05-31
@Diel

I suspect (not a nasm expert) that the instruction
does not do what you want. Most likely, dword num2 takes the address num2, since in x86 there is no opcode "subtract from the number at address ___ the number at address ___", only the subtraction of a constant.
You need something like:

mov ebx, [num1]
mov ecx, [num2]
sub ebx, ecx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question