www.xbdev.net xbdev - software development
Thursday April 27, 2017
home | about | contact | Donations

     
 

Assembly Language

What every pc speaks..1010...

 

C to Assembly...

 

{Under Construction}

 

With a bit of knowledge comes great power!  To be able to look at assembly and know how it would look in C is a great thing..... for one, it allows you to see what other people have written in C, without even looking at there C code...mhahaha.

 

A great way to explore other peoples compiled code is with some dissasembers, such as hackman or mdasm ...or even winhex :)

 

 

Now Lets take a look at loops... as loops are a sweet way of doing things over and over again with a relatively few lines of code.... Take a look how much C simplifies our lives.... but also notice how you could optimise that assembly if you had your way :)

 

Comparison: ForLoop

      int b=0;

      for( int i=0; i<10; i++ )

      {

            b++;

      }

 

 

;_b$ = -4
;_i$  = -8

            mov      DWORD PTR _b$[ebp], 0      ; b=0

; Loop Initilisation

            mov      DWORD PTR _i$[ebp], 0

            jmp      SHORT $L269

 

; Perform some function, each time we loop

$L270:

            mov      eax, DWORD PTR _i$[ebp]

            add      eax, 1

            mov      DWORD PTR _i$[ebp], eax

 

; Check the i<10, if its false, then we exit the loop

$L269:

            cmp      DWORD PTR _i$[ebp], 10

            jge        SHORT $L271

 

            mov      ecx, DWORD PTR _b$[ebp]    ; b++      /|\

            add      ecx, 1                                        ;  b++    body

            mov      DWORD PTR _b$[ebp], ecx    ; b++      \|/

 

            jmp      SHORT $L270

$L271:

 

 

Another example C that is worth taking a look at, is if's ....e.g. if(true) then do this.... now this should be nice and simple, well I hope it is...

 

 

Comparison: If

     

      int b=0;

      if( b==0 )

      {

            b++;

      }

 

 

;_b$ = -4
 

            mov      DWORD PTR _b$[ebp], 0      ; b=0

 

; Check if b is zero, and set any flags, in the flags registers

            cmp      DWORD PTR _b$[ebp], 0

            jne        SHORT $L268

 

; Well if where here, then it was true

            mov      eax, DWORD PTR _b$[ebp]      ; b++      /|\

            add      eax, 1                                           ; b++    body

            mov      DWORD PTR _b$[ebp], eax      ; b++      \|/

 

; If failed so it jumps straight here

$L268:

 

 

 

 

 

 

 

 

 

 

 

 

 
 Visitor: 9534626  { 209.237.238.175 } Copyright (c) 2002-2017 xbdev.net - All rights reserved.
Designated tutorial and software are the property of their respective owners.