[QUOTE=meromarololo2]...
Now my Questions:
1:
Code:
void ZeroArray(void* RCX, int EDX);Sets all bytes from *RCX to *RCX+EDX to 0 What does he means by those comments?
Ram is a large continuous row of boxes, numbered 1 - some huge number which is how much ram you have (1 gig, 2, 8, 16 etc).
Set all bytes (starting at some #, and stopping at some #), so like from box # 1,000,000 to # 3,000,00, will all get set to 0.
EDX = the size of the array (ie. the number of bytes to clear)
So RCX to RCX+EDX is like saying 1,000,000 to (1,000,000 + 100) -- for a 100 byte array. Point being, rcx = start address, rcx+edx = stop address.
2:
Code:
mov ax, 0 ;Set ax to 00 , What does he mean by 00? why not 0?
Anything after the semi-colon is a comment. 00 is the same as 0. The programmer's preference/ typo - not significant. 00 = 0 = 00000000
3:
Code:
mov r8d, edx ;Save the original count to r8d Original count? what does he mean by that? also we don't know what's the value of edx right?
The instruction basically translates to "MOVE into r8d, the value of edx" - ie. make a COPY of edx and store it in r8d.
False. We DO know the value of edx --> in C++ when you pass in arguments to a function, it will place them in registers (first rcx, then rdx -- I don't know off top of my head -- the videos explain calling convention / passing parameters). So in this example, we know...rcx = the first parameter (a memory address to the beginning of the array) and edx = the 2nd parameter, the # of items in the array.
4:
Code:
shr edx, 1 ;Halve the count because we are using AX, not AL What does he mean by his comment? hauving a 1? what the..??
Shifting right 1 bit is the same as dividing by 2. Shifting right 2 bits is dividing by 4, 3 bits = 8, 4 bits = 16 etc etc.
He divides by 2 because we're working with WORDS, which is 2 bytes at a time. So if count was 100, we only need to move 2 bytes 50 times. The more bytes you move at a time, the less times you have to move bytes. If we were doing 4 bytes at a time we'd use "mov dword ptr [rcx], eax ;Sets 4 bytes to 0" and "add rcx 4".
5:
Code:
mov word ptr [rcx], ax ; but does he mean by that code: (move the value of ax which has type word to the pointer rcx?) or im wrong? if im wrong PLEASEE explain this code correctly
You're correct. So, a WORD is 2 bytes. Assume RCX = some random number --> that number box will get the FIRST BYTE of ax, and that number box + 1 will get the SECOND byte of ax. 2 boxes of ram are used to store the value of ax.
6:
Code:
add rcx, 2 ;Moves rcx to the next 2 bytes Doesn't that mean that he adds 2 to the value of rcx? Why then he says in comment "MOVE TO NEXT 2 BYTES"??
Registers store numbers. Ram boxes have a number associated with them. See the connection?? If RCX = 5 then reading [rcx] is the same as [5] which will read the value of box 5. By increasing the register, the next time you use [reg], it will point to a different box.
7:
Code:
dec edx ;Decrement our counter ; Why in the comment he said "counter"? isnt the counter>> cx? why he says dx is the counter?
Not sure, haven't looked over the code as a whole. If he said, I'm sure he's using it as a counter...or a typo..idk. Translates to "subtract 1 from register"..basic. edit: looking at his asm prototype, he shows which registers get the values passed in.
"; void ZeroArray(void* RCX, int EDX)" ie rcx = start address, edx = count (size of array)
8:
Code:
and r8d, 1 ;Check if there was an even number
What does that mean?[/code]
in BINARY, the RIGHTMOST digit (ie digit 0) can only have a value of 0 or 1 --> if that BIT is set, it means that number is odd. Any odd number will always have the very first bit set to 1. And any even number will always have that bit set to 0. Basic Binary. Calling "and r8d, 1" will check if that bit is set and set the FLAGS register.
-Hope that helps a little. His videos explain it better than I can.