flat assembler
Message board for the users of flat assembler.
Index
> Main > What's the easiest way to have the opposite of a number ? |
Author |
|
a115433 29 Apr 2010, 15:27
neg?
it will substract it from 0. |
|||
29 Apr 2010, 15:27 |
|
vanzan 29 Apr 2010, 15:28
Oh ! I've forget that the result was stock into BX --"
Correst code: Code: MOV [tttest],10 MOV AX,-1 IMUL [tttest] MOV [tttest],BX CMP [tttest],(-10) JE cici invoke WriteConsole, [stdout], "don't" , 5, NULL, NULL cici: invoke WriteConsole, [stdout], "work" , 4, NULL, NULL |
|||
29 Apr 2010, 15:28 |
|
Madis731 29 Apr 2010, 15:44
1) neg [ttest]
2A) not [ttest] \ inc [ttest] 2B) xor [ttest],-1 \ inc [ttest] Actually mul puts the result into dx:ax or edx:eax or rdx:rax, but NOT in the BX EDIT: my mistake removed imul bx,[ttest],-1 imul bx,-1 etc. but why would you use multiplication when its slow and hard to do? NEG-instructions is exactly designed for this! Last edited by Madis731 on 29 Apr 2010, 16:18; edited 1 time in total |
|||
29 Apr 2010, 15:44 |
|
baldr 29 Apr 2010, 15:56
Madis731 wrote: imul never touches more than the registers you give it. |
|||
29 Apr 2010, 15:56 |
|
LocoDelAssembly 29 Apr 2010, 16:04
Quote: 1) neg [ttest] Perhaps I misunderstood your point but if that was supposed to show equivalence then this would be correct: 1) not [ttest] 2) xor [ttest], -1 |
|||
29 Apr 2010, 16:04 |
|
Madis731 29 Apr 2010, 16:19
I'm sorry - fixed - I got so excited about the multiplication usage that I wrote faster than I thought... sorry...
|
|||
29 Apr 2010, 16:19 |
|
vanzan 29 Apr 2010, 18:30
Quote:
Because I didn't learnt this very useful "command" at my IT school ^^ Thanks, a lot ! It can't be more simple Edit: (I'm talking about "neg" operater) |
|||
29 Apr 2010, 18:30 |
|
edfed 29 Apr 2010, 19:52
in assembly, we don't say comand, but INSTRUCTION. say this to your teacher.
another way: Code: xor eax,eax sub eax,[ttest] but franckly, none better than Code: neg [ttest] |
|||
29 Apr 2010, 19:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.