Тёмный
No video :(

Comparing C to Assembly 

The Builder
Подписаться 20 тыс.
Просмотров 6 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 19   
@PianoElipse
@PianoElipse 7 месяцев назад
for increment in assembly we have "INC" instruction which also works with memory pointers, like: inc dword [rsp+04h]
@bradt5426
@bradt5426 6 месяцев назад
Amazing video, thank you! Ive never had a good experience trying to learn ASM, but this was a great overview.
@hydradragonantivirus
@hydradragonantivirus 7 месяцев назад
What happens when we add library.
@TheBuilder
@TheBuilder 7 месяцев назад
You get more assembly to read
@baranjan6969
@baranjan6969 7 месяцев назад
This website seems AWESOME ngl
@kipchickensout
@kipchickensout 7 месяцев назад
I've always wondered, in e.g. MOV you use square brackets if you want to basically dereference a pointer (e.g. EBP-1 being an address) but in LEA the address is specified in [brackets] even though we're not dereferencing anything, and just use the address itself - all I could find after researching it online is that "it's just how it is" in some stackoverflow post and 15 people telling eachother they're wrong
@jbird4478
@jbird4478 7 месяцев назад
The brackets are to indicate that the operand is a memory reference. That is always the case for LEA, because it has a register as a destination operand, and a memory reference as a source operand. In the case of MOV there are different forms. MOV eax, ebx will move the contents of ebx, and MOV eax, [ebx] treats ebx as a memory operand and moves whatever is at that address. These operands are encoded differently. If you would write LEA eax, ebx you would be telling the assembler to encode two register operands, which is not valid for a LEA instruction. Assembly has no concept of pointers or dereferencing. It just has register, memory, and immediate operands. Memory operands can contain base, index, scale, and offset numbers. That's why using LEA one can effectively do some arithmetic. Compilers sometimes use it for normal integer arithmetic as well, because it provides a quick way to do multiplication and addition. Register operands only allow the register itself to be named, so LEA eax, ebx-4 would not be possible. LEA eax, [ebx-4] makes it a memory operand, with the contents of ebx as base, and -4 as offset.
@kipchickensout
@kipchickensout 7 месяцев назад
@@jbird4478 makes sense, but wouldn't MOV EAX, some_addr be the same as LEA EAX, [some_addr]? if yes, i guess using LEA for this is just a convention? I get the general gist, I've actually seen what you meant with arithmetic a few days ago when i was looking at some code in sharplab and it used LEA for adding two numbers :)
@jbird4478
@jbird4478 7 месяцев назад
@@kipchickensoutMOV eax, some_addr means you pass some_addr as an _immediate._ Then it really just a number that it stores in the register. If some_addr is a symbol, the linker will hardcode the value of that symbol directly in that instruction. That is not how LEA is used. That is used to calculate an address. What you will often see is things like LEA eax, [ebx+4]. That takes the number currently in ebx, adds 4 and stores the result in eax. It just calculates an address. A MOV eax, [ebx+4] will perform the same calculation, but instead of storing that address in eax, it stores whatever is at that address. MOV eax, ebx+4 would not be valid, because it is not a register operand, not an immediate number, and not a memory operand. With brackets, it becomes a memory operand, but then it'll mov what is at that memory address, not the address itself. That is what LEA is for. This is particularly useful because on modern systems, absolute numbers as memory addresses are almost non-existent. Programs are loaded at random addresses, and almost everything is addressed relative to something else. Imagine you have the address of a structure in ebx, and you need the address of a member of that structure. Then its LEA eax, [ebx+offset of that member]. If you need the value of that member: MOV eax, [ebx+offset].
@PianoElipse
@PianoElipse 7 месяцев назад
I also would like to see how code would look like when we using an optimization (like /O2, /O3, /O1).
@pablo.v.roldan
@pablo.v.roldan 6 месяцев назад
why doesnt it add 1 instead of doing the variable change when i+=?
@rejisha
@rejisha 6 месяцев назад
Could it do it the other way. Like you write ASM and it turns it into C counterpart?
@TheBuilder
@TheBuilder 6 месяцев назад
Try using a decompiler
@dschwob
@dschwob 7 месяцев назад
Nice video. Whats the software?
@TheBuilder
@TheBuilder 7 месяцев назад
It's called compiler explorer
@TheBuilder
@TheBuilder 7 месяцев назад
You need to download the website
@dschwob
@dschwob 7 месяцев назад
@@TheBuilder Its seems realy usefull
@musprodev
@musprodev 7 месяцев назад
First sir 😼😊
@maximsl
@maximsl 6 месяцев назад
Very uneffective and slow assembly code.
Далее
C++ std::bind tutorial and why lambdas are better
9:01
Кого из блогеров узнали?
00:10
Просмотров 567 тыс.
why do void* pointers even exist?
8:17
Просмотров 356 тыс.
To-Do App in Assembly
1:05:27
Просмотров 122 тыс.
Comparing C to machine language
10:02
Просмотров 5 млн
Dynamic Arrays in C
11:46
Просмотров 66 тыс.
WHY IS THE STACK SO FAST?
13:46
Просмотров 149 тыс.
Linus Torvalds "Nothing better than C"
1:28
Просмотров 1,4 млн
How to Call Assembly Code from C
3:46
Просмотров 30 тыс.
Torvalds Speaks: Rust's Impact on the Linux Kernel
3:50
I made the same game in Assembly, C and C++
4:20
Просмотров 711 тыс.
Pointer and Array Differences Explained In 2 Minutes
2:40