NASM Forum > Programming with NASM
What is the difference between “4 - 12” and “4 + (-12)”?
(1/1)
danny:
Hello. I try to compare the next expressions:
1)
mov al, 4
mov bl, 12
sub al, bl ; CF == 1
0000 0100 (4)
+
1111 0100 (-12)
=
1111 1000 (-8 == 248)
2)
mov al, 4
mov bl, -12
add al, bl ; CF == 0
0000 0100 (4)
+
1111 0100 (-12)
=
1111 1000 (-8 == 248)
The results are identical, but carry flags are not. Why? The subtraction realized by addition to twos complement value.
Frank Kotler:
Hi Danny,
Welcome to the forum.
--- Quote from: danny on November 20, 2020, 11:33:45 PM ---Hello. I try to compare the next expressions:
1)
mov al, 4
mov bl, 12
sub al, bl ; CF == 1
0000 0100 (4)
+
1111 0100 (-12)
--- End quote ---
But that isn't what you're doing.
0000 1100 (12)
Subtracting that sets the carry flag. Adding -12 does not.
Best,
Frank
.
danny:
Sorry, but I do not understand. Can you explain me why it is so. The subtraction realized by addition to twos complement value. Isn't it?
danny:
I think, when we sub something that is equal to add, but by addition to twos complement value. And when we get twos complement value CPU inverted bits (neg, when we use neg command CF = 1) and then as the result we have CF = 1. Is it so?
Frank Kotler:
Hi Danny,
You are correct that "neg" sets CF But "sub". is a separate instruction... as you show...
Best,
Frank
Navigation
[0] Message Index
Go to full version