COULD SOME1 ANSWER MY QUESTIONS ABOUT THIS ASM CODE?
This is the cpp file:
This is the asm file
This is the header file
Now my Questions:
First : the ASM file:
1:
What does he means by those comments?
2:
, What does he mean by 00? why not 0?
3:
Original count? what does he mean by that? also we don't know what's the value of edx right?
4:
What does he mean by his comment? hauving a 1? what the..??
5:
this one i want u to explain every single code of it , in the commenet why he writes "sets 2 bytes"? i know that in asm "word"=2bytes,"dword"=4bytes, and so on.. , 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
6:
Doesn't that mean that he adds 2 to the value of rcx? Why then he says in comment "MOVE TO NEXT 2 BYTES"?? correct me guys and tell me what's the right explanation
7:
Why in the comment he said "counter"? isnt the counter>> cx? why he says dx is the counter?
8:
What does that mean?
Few little questions hah?
NB: I Finished C++ by watching 75 vidoe tuts, and made lots of project where their folder is 1 gega+, but im newbie to assembly..
Code:
#include <iostream>
#include <conio.h>
#include <ctime>
#include "headerfile.h"
using namespace std;
int main()
{
int count = 1024;
char *arr = new char[count];
/* init the array to contain random numbers just so it's easy to tell that our procedure has worked*/
for(int i = 0; i < count; i++) arr[i] = (char)rand();
//Print down the initial values
for(int j = 0; j < count;j++) cout<<(int)arr[j]<<" ";
//Call our procedure
ZeroArray(arr, count*sizeof(char));
//Print out the values again to make sure they are all 0
for(int j = 0; j < count;j++) cout<<(int)arr[j]<<" ";
_getch(); //Prevent the window from closing
delete[] arr; //Free our memory
return 0;
}
Code:
.code ; void ZeroArray(void* RCX, int EDX) ;Sets all bytes from *RCX to *RCX+EDX to 0 ZeroArray proc cmp edx, 0 ;Check for 0 or less jle Finished cmp edx, 1 ;Check for 1 je SetFinalByte mov ax, 0 ;Set ax to 00 mov r8d, edx ;Save the original count to r8d shr edx, 1 ;Halve the count because we are using AX, not AL MainLoop: mov word ptr [rcx], ax ;Sets 2 bytes to 0 add rcx, 2 ;Moves rcx to the next 2 bytes dec edx ;Decrement our counter jnz MainLoop ;Jump if we have more to set and r8d, 1 ;Check if there was an even number jz Finished ;If ther was, we are done. SetFinalByte: mov byte ptr [rcx], 0 Finished: ret ZeroArray endp end
Code:
#ifndef ZERYARRAY_H #define ZEROARRAY_H // Set CountInBytes bytes to 0 starting from &arr and moving to &arr + CountInBytes extern "C" void ZeroArray(void *arr, int CountInBytes); #endif
First : the ASM file:
1:
Code:
; void ZeroArray(void* RCX, int EDX) ;Sets all bytes from *RCX to *RCX+EDX to 0
2:
Code:
mov ax, 0 ;Set ax to 00
3:
Code:
mov r8d, edx ;Save the original count to r8d
4:
Code:
shr edx, 1 ;Halve the count because we are using AX, not AL
5:
Code:
mov word ptr [rcx], ax ;Sets 2 bytes to 0
6:
Code:
add rcx, 2 ;Moves rcx to the next 2 bytes
7:
Code:
dec edx ;Decrement our counter
8:
Code:
and r8d, 1 ;Check if there was an even number
Few little questions hah?
NB: I Finished C++ by watching 75 vidoe tuts, and made lots of project where their folder is 1 gega+, but im newbie to assembly..
:



