Похожие чаты

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 ответов

8 просмотров

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

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

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

Вопрос по диагностике ошибок (я знаю в чем, в данном конкретном примере, я знаю, как исправить, пример модельный, понятно, что в реальности бывает намного запутаннее). module...
ⰄⰎⰋⰐⰐⰑⰛⰤⰧⰧⰩⰄ ⰊⰑⰁⰓⰡⰛⰦⰕⰫ
10
А дальше что?.. Записать в файл, потом в Код?.. И потом разбирать как-то?..
Хаскель Моисеевич Гопник
14
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
52
А чем вам питонисты не угодили?😂
.
79
Asus, норм фирма для ноутов?
Артем Записной
20
доброго времени. db, dw и прочие исполняются при трансляции или при выполнении программы?
lutayyy
10
И ещё - определить, имеет ли он доступ к интернету очень просто - смотрим всех пользователей сети. И да, как оно без сети передаст данные в куда то?
BytePixel 🐧
15
Ясн. Но я всеравно к кедам отношусь с опасением. Чисто субьективное кедосозерцание. Что касаемо "восторга изяшности кед" так и не вкурил, хотя много слышал, пока не поставил с...
Артем Записной
30
Hi guys which one is better ?
A
12
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
Карта сайта