Skip to main content

Posts

Showing posts with the label ebp

The Additon & Subtraction in Assembly

There is not much difficulty when it comes to addition and subtraction in assembly programming. Simply, additon and substraction breaks down to the following: add eax , ecx ; eax = eax + ecx, result in eax add eax , DWORD [ ebp - 4 ] ; eax = eax + localVar1, result in eax add DWORD [ ebp - 4 ] , DWORD [ ebp -4 ] ; illegal, with all instruction both operands can never be memory add DWORD [ ebp - 4 ] , eax ; [ebp-4] = [ebp-4] + eax sub eax , ecx ; eax = eax - ecx, result in eax sub eax , DWORD [ ebp - 4 ] ; eax = eax - localVar1, result in eax sub DWORD [ ebp - 4 ] , DWORD [ ebp -4 ] ; illegal, with all instruction both operands can never be memory sub DWORD [ ebp - 4 ] , eax ; [ebp-4] = [ebp-4] - eax A simple program to display the message about an arithetic operation like "Math: 8 + 4 = ?" can be achived b

Important Lessons to Remember from Assembly Language programming

Okay, so I have been writing assembly language programs for a little bit now and to be honest with everyone, not like it is not obvious, assembly can be very frustrating especially when you write code and it seems to make logical sense.  However, when you run the program, it either says segmentation fault, memory corruption issues, or the program displays a bunch of random text to the screen. Okay so, recently I have been trying to write an application that does something simple using assembly.  The goal was to write a program with Nasm and have it display the number of arguments passed to our program. From my previous posts, we know that ebp+4 contains the return address after the main method is executed.  We also now that ebp+8 is the first parameter passed to main,  ebp+12 is the second parameter, and so on and so on with 4 added to each time.  This is because from the C programming language the main method has a header declaration that is of the following syntax: int main(in