Assembly Code - Basic "Hello World!" application

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Assembly Code - Basic "Hello World!" application

Post by -Th3V01d- on Fri Jan 27, 2012 8:56 am
([msg=63913]see Assembly Code - Basic "Hello World!" application[/msg])

Hello,

Assembly Code is hardest(i think) programming language in whole world! its low-level programming language because when you compile and run your assembly application you are directly contacting with Microprocessor and you are closest to hardware. Assembly code isn't like other high-level languages, for example you can't make a program for Graphis card or you can't assembly nothing with C++. Many operating systems are maked in Assembly Code (Linux, DOS...). Every compiled Assembly application is coded directly in binary code.

Im gonna show you basic text printing program in assembly.
Code: Select all
ORG 100h
        mov ah, 09
        mov dx, msg
        int 21h
        mov ah, 01
        int 21h
        mov ah, 4Ch
        int 21h
        msg db 'Hello World!', 0Ah, '$'

Now explanation:

That is place in memory where we want to put our program. Thats standard for basic programs. In english it means "ORGANIZE 100h" 100h is hexadecimal number.
Code: Select all
ORG 100h


We are moving a value of 9 in AH, but whats AH? every processor have 4 general registers where he stores data(ax,bx,cx,dx), AH means A HIGH, why HIGH? because we want to set register A to run first, or if we type AL(wich means A LOW) the A register will run after all HIGH set registers are executed. There is alot of register 16-bytes register, 32-byt and 64-byt. These ones are 16-byt. And by the way why we are moving 9 bytes in AH? because when we move 9 thats means that we are going to print some text.
Code: Select all
mov ah, 09


This one means that we are creating and moving variable "msg" to dx register. If you want to print some text in assembly applications you are need to create variable and give it a value(insert a text in variable).
Code: Select all
mov dx, msg


Int 21h means that you are going to execute all command that you are typed above, and to stop all other.(mov dx, msg and other...)
Code: Select all
int 21h


We are moving a value of 1 to register ah, we told microprocessot that we are making PAUSE command in program, so the program will wait keyboard input.
Code: Select all
mov ah, 01


This means, after keyboard input, exit the program.
Code: Select all
mov ah, 4Ch


And finaly! we are giving string value to our 'msg' variable! and then print it.
Code: Select all
msg db 'Hello World!', 0Ah, "$"


Happy Coding!

-Th3V01D- :ugeek:
ImageДа будет Революция
User avatar
-Th3V01d-
New User
New User
 
Posts: 11
Joined: Sun Jan 15, 2012 8:24 am
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by centip3de on Fri Jan 27, 2012 9:49 pm
([msg=63927]see Re: Assembly Code - Basic "Hello World!" application[/msg])

-Th3V01d- wrote:Hello,

Assembly Code is hardest(i think) programming language in whole world! its low-level programming language because when you compile and run your assembly application you are directly contacting with Microprocessor and you are closest to hardware. Assembly code isn't like other high-level languages, for example you can't make a program for Graphis card or you can't assembly nothing with C++. Many operating systems are maked in Assembly Code (Linux, DOS...). Every compiled Assembly application is coded directly in binary code.

Im gonna show you basic text printing program in assembly.
Code: Select all
ORG 100h
        mov ah, 09
        mov dx, msg
        int 21h
        mov ah, 01
        int 21h
        mov ah, 4Ch
        int 21h
        msg db 'Hello World!', 0Ah, '$'

Now explanation:

That is place in memory where we want to put our program. Thats standard for basic programs. In english it means "ORGANIZE 100h" 100h is hexadecimal number.
Code: Select all
ORG 100h


We are moving a value of 9 in AH, but whats AH? every processor have 4 general registers where he stores data(ax,bx,cx,dx), AH means A HIGH, why HIGH? because we want to set register A to run first, or if we type AL(wich means A LOW) the A register will run after all HIGH set registers are executed. There is alot of register 16-bytes register, 32-byt and 64-byt. These ones are 16-byt. And by the way why we are moving 9 bytes in AH? because when we move 9 thats means that we are going to print some text.
Code: Select all
mov ah, 09


This one means that we are creating and moving variable "msg" to dx register. If you want to print some text in assembly applications you are need to create variable and give it a value(insert a text in variable).
Code: Select all
mov dx, msg


Int 21h means that you are going to execute all command that you are typed above, and to stop all other.(mov dx, msg and other...)
Code: Select all
int 21h


We are moving a value of 1 to register ah, we told microprocessot that we are making PAUSE command in program, so the program will wait keyboard input.
Code: Select all
mov ah, 01


This means, after keyboard input, exit the program.
Code: Select all
mov ah, 4Ch


And finaly! we are giving string value to our 'msg' variable! and then print it.
Code: Select all
msg db 'Hello World!', 0Ah, "$"


Happy Coding!

-Th3V01D- :ugeek:


Hmmm... Well, you should really work on your low-level knowledge. For instance;

Assembly Code is hardest(i think) programming language in whole world!


It's actually the easiest language (in my opinion), just has a different syntax. I say it's the easiest because there are no pre-built functions to remember, no awkward syntax per function, it's easy.

for example you can't make a program for Graphis card or you can't assembly nothing with C++


You can actually do both. To make a program for the Graphics card, you have to directly program into it. I mean, how else do you think other programs, that are assembled into assembly language are made? I don't really understand what you mean by 'you can't assembly nothing with C++' , but I'm assuming you mean 'you can't use assembly with C++' , which is also false. In-line ASM is quite common when building things like; graphics drivers (though this are occasionally in pure ASM), game engines, graphics libraries (once again, also can be in pure ASM), and the likes.

Many operating systems are maked in Assembly Code (Linux, DOS...).


Those were both made with C, and some ASM (not too sure about DOS, but I believe so). OS's these days are primarily coded in C, and only use ASM when they absolutely need it.

Another thing; throughout the entire thing, you're saying that you're communicating with a microprocessor, when you're actually communicating with the CPU of your computer. Also, work on your English more before you post more long posts like that trying to explain things. Lastly, ASM _isn't_ an interpreted language, or a compiled language. It's an assembly language. Other than that, good job, and keep going!

~Cent
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by tgoe on Fri Jan 27, 2012 9:51 pm
([msg=63928]see Re: Assembly Code - Basic "Hello World!" application[/msg])

Sorry to pick apart your english but I think some things need to be clarified.

I think, technically, assembly source code is simply assembled. i.e., it's basically a 1:1 translation of mnemonic to opcode.

I'm not sure what you mean by:
... can't make a program for Graphis card ...

but check out http://en.wikipedia.org/wiki/Demoscene lol

Anything you write in any programming language can also be written in assembly.

You can do assembly in C/C++ with:

Code: Select all
__asm__("assembly code here");
/* or maybe */
asm("assembly...");


Most every OS has a bit of assembly as required by the platform it runs on. But I can think of only a couple modern, general OSes written in assembly: a-Linux, Menuet.

If you want something harder than assembly, give 'Brainfuck' a shot.

-- Fri Jan 27, 2012 9:55 pm --

@centip3de:

brofist requested.
User avatar
tgoe
Contributor
Contributor
 
Posts: 629
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by centip3de on Fri Jan 27, 2012 10:55 pm
([msg=63930]see Re: Assembly Code - Basic "Hello World!" application[/msg])

tgoe wrote:@centip3de:

brofist requested.


Brofist accepted.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by LoGiCaL__ on Sun Jan 29, 2012 3:17 am
([msg=63965]see Re: Assembly Code - Basic "Hello World!" application[/msg])

-Th3V01d- wrote:Hello,

Assembly Code is hardest(i think) programming language in whole world!


http://www.webopedia.com/TERM/M/machine_language.html

http://en.wikipedia.org/wiki/Machine_language
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1060
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by -Th3V01d- on Sun Jan 29, 2012 7:56 am
([msg=63968]see Re: Assembly Code - Basic "Hello World!" application[/msg])

i know im not good with assembly, but i just wanted to show people how to write basic Hello World program... and about C++.... you can't programme hardware with C++... he is high-level language and its not close to hardware... C++ is just for applications :!:
ImageДа будет Революция
User avatar
-Th3V01d-
New User
New User
 
Posts: 11
Joined: Sun Jan 15, 2012 8:24 am
Blog: View Blog (0)


Re: Assembly Code - Basic "Hello World!" application

Post by mShred on Sun Jan 29, 2012 3:23 pm
([msg=63979]see Re: Assembly Code - Basic "Hello World!" application[/msg])

-Th3V01d- wrote:i know im not good with assembly, but i just wanted to show people how to write basic Hello World program... and about C++.... you can't programme hardware with C++... he is high-level language and its not close to hardware... C++ is just for applications :!:

A large portion on Unix was written in C.
Image

For those about to rock.
User avatar
mShred
Administrator
Administrator
 
Posts: 1687
Joined: Tue Jun 22, 2010 4:22 pm
Blog: View Blog (2)


Re: Assembly Code - Basic "Hello World!" application

Post by centip3de on Sun Jan 29, 2012 3:48 pm
([msg=63989]see Re: Assembly Code - Basic "Hello World!" application[/msg])

-Th3V01d- wrote:i know im not good with assembly, but i just wanted to show people how to write basic Hello World program... and about C++.... you can't programme hardware with C++... he is high-level language and its not close to hardware... C++ is just for applications :!:


You can write operating systems in C++...
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests