I Learned Basic ASM ( Assembly )

I decided to move back to Windows so I can continue to program the way I want to program. After I moved, I started learning some ASM language so I can combine it with my basic C++ skills that are improving :).

First this is pure ASM that displays 3 things.

OUTPUT:

Hello World.

My Name Is Jonathan Vasquez.

This Is Assembly.

ORG 100h
JMP START

; Variables ~

EnterX db “”,10,13,”$”
HelloWorld db “Hello World.”,10,13,”$”
MyNameIsJV db “My Name Is Jonathan Vasquez.”,10,13,”$”
ThisIsASM db “This Is Assembly.$”

; ~

START:
MOV AH,09
MOV DX,EnterX
INT 21h
MOV AH,09
MOV DX,HelloWorld
INT 21h
MOV AH,09
MOV DX,MyNameIsJV
INT 21h
MOV AH,09
MOV DX,ThisIsASM
INT 21h
MOV AH,09
MOV DX,EnterX
INT 21h
JMP ENDx

ALTENDx:
MOV AH,4Ch
MOV AL,00
INT 21h
ENDx:
MOV AX,4C00h
INT 21h

In pure C++ that code would be identical to this:

#include <iostream>

using std::cout;

using std::endl;

using std::cin;

int main()

{

cout << “Hello World.” << endl;

cout << “My Name Is Jonathan Vasquez.” << endl;

cout << “This is Assembly ( well it’s C++ here šŸ™‚ )”;

return 0;

}

Now I learned how to combine my basic knowledge of ASM into my basic knowledge of C++.

The following was just a test to see if I can take the basic statement in c++ of “first = second”, and make it work with ASM inside C++.

The program first prints out the values of first and second before being made equal to each other, after that it goes into ASM to make them equal and after that it jumps back into C++ to print out if the ASM worked.

OUTPUT:

Value of First: 1
Value of second: 0
Value of First: 1
Value of second: 1

And the code is:

#include <iostream>

int main()
{
int first = 1;
int second = 0;

std::cout << “Value of First: ” << first <<
“\nValue of second: ” << second;

__asm
{
MOV EAX,first
MOV second,EAX;
}

std::cout << “\nValue of First: ” << first <<
“\nValue of second: ” << second;

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: