flat assembler
Message board for the users of flat assembler.
Index
> Main > About cbw,cwde,cwd,cdq |
Author |
|
Roman 25 Apr 2023, 10:20
Why need cbw,cwde,cwd,cdq ?
cbw — sign-extend byte in al to word in ax. Why do this ? Show example task where is needed cbw,cwde,cwd,cdq. |
|||
25 Apr 2023, 10:20 |
|
Roman 25 Apr 2023, 10:27
O !
|
|||
25 Apr 2023, 10:27 |
|
Roman 25 Apr 2023, 10:27
I found. For negative numbers.
Code: xor eax,eax mov al,-5 ;-5=255-5=251 cbw ;in ax=-5 but 16bits 65535-5 |
|||
25 Apr 2023, 10:27 |
|
macomics 25 Apr 2023, 11:17
Forgot cqo. rax => rdx:rax
|
|||
25 Apr 2023, 11:17 |
|
macomics 25 Apr 2023, 11:27
In order not to ask such questions, it is enough to read about the additional format of numbers.
https://en.wikipedia.org/wiki/Two%27s_complement#Sign_extension |
|||
25 Apr 2023, 11:27 |
|
revolution 25 Apr 2023, 11:33
I think a lot of confusion happens if someone implicitly extends values with zeros.
The following might not be true: 0xFB == 0x00FB We need to justify whether extending to the left with zeros is correct, or whether extending with the top-most bit is correct. And it depends upon the context. |
|||
25 Apr 2023, 11:33 |
|
Roman 25 Apr 2023, 11:35
macomics wrote: Forgot cqo. rax => rdx:rax Why out to rdx:rax ? |
|||
25 Apr 2023, 11:35 |
|
Roman 25 Apr 2023, 11:38
Oh !
Code: mov al,-5 ;al=FB movsx ax, al ;the same work as cbw ! I checked in IDA Pro ax=FFFB ;more handful then cbw,cwde,cwd movsx edx,cl movsx dx,cl movsx edx,cx Crazy Intel Last edited by Roman on 25 Apr 2023, 12:09; edited 7 times in total |
|||
25 Apr 2023, 11:38 |
|
revolution 25 Apr 2023, 11:38
Roman wrote:
|
|||
25 Apr 2023, 11:38 |
|
macomics 25 Apr 2023, 12:13
revolution wrote:
|
|||
25 Apr 2023, 12:13 |
|
DimonSoft 27 Apr 2023, 14:30
Roman wrote: Oh ! It’s just important to note that movsx and movzx didn’t exist before 80386. |
|||
27 Apr 2023, 14:30 |
|
Ali.Z 16 May 2023, 18:23
you can play with the snippet here, trying removing cdq and see what happen.
https://board.flatassembler.net/topic.php?t=22616 _________________ Asm For Wise Humans |
|||
16 May 2023, 18:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.