Похожие чаты

Hello, I have been learning about assembly by disassembling a

c code (the target part is the loop which copies some characters from one array to another array.
the code was compiled with -O0

the code is commented only for the first iteration

| ; CODE XREF from sym.testArr @ 0x140001592
.--> 0x14000156d mov eax, dword [var_8h] ; eax = i = 0
:| 0x140001570 movsxd rdx, eax ; mov eax to rdx, and sign extend it... rdx = 0
:| 0x140001573 mov rax, qword [var_10h] ; rax = addr of arr
:| 0x140001577 add rax, rdx
:| 0x14000157a movzx edx, byte [rax] ; edx = a, and zero extend
:| 0x14000157d mov eax, dword [var_4h] ; eax = 6
:| 0x140001580 cdqe
:| 0x140001582 mov byte [rbp + rax - 0xf], dl ; *(rbp + rax - 0xf) = dl = 'a'
:| 0x140001586 sub dword [var_4h], 1 ; num--
:| 0x14000158a add dword [var_8h], 1 ; i++
:| ; CODE XREF from sym.testArr @ 0x14000156b
:`-> 0x14000158e cmp dword [var_8h], 6 ; i <=6
`==< 0x140001592 jle 0x14000156d

so, I had a question regarding the first two instructions
why does the compiler set the eax register to 0, then copies the value to rdx, and then another valu copied to it?
can't the value at var_8h be copied to rdx directly? or will it have some side effects when it goes that way?

6 ответов

13 просмотров

Do you have the original code? A very cool website is godbolt.org

No, there's no side effect. It could have been written movsxd rdx, dword [var_8h] It's pretty normal to see useless steps at -O0 optimization level.

void *- Автор вопроса
Mmmmm.....
No, there's no side effect. It could have been wr...

thanks.. hadn't seen this initially (i was in some session at the same time)

how did you produced this?

void *- Автор вопроса
Alejandro
Do you have the original code? A very cool website...

the c code: https://paste.centos.org/view/42027307 assembly code for testArr(): https://paste.centos.org/view/d38ee7b6

void *- Автор вопроса
Déjà vu
how did you produced this?

disassembled with radare2

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта