7 Replies - 1465 Views - Last Post: 15 February 2010 - 10:58 PM

#1 Aaronugio   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-October 09

What is Assembly?

Post icon  Posted 28 January 2010 - 05:40 PM

I've heard butt loads about how incredibly hard Assembly is, and i like the sound, but, before I get started learning it, I figured I ought to know what it really is, and what it does?

I believe I understand that 8086 is an intel language, yes?
That's about all I even think I know, lolz.
If someone could give me a description of how it works? or point me to a learning resource?

Thank you so much you guys!!

Is This A Good Question/Topic? 0
  • +

Replies To: What is Assembly?

#2 numeric   User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 77
  • Joined: 12-January 09

Re: What is Assembly?

Posted 28 January 2010 - 08:20 PM

Assembly is a very low level language that requires you to directly modify the memory in which it is stored to run your code. It can be a struggle to learn to begin with, but it's also very rewarding, especially when debugging problems like stack overflows or segmentation faults in conventional programs. You'll need to learn about how memory is organised, what the stack is and how it is manipulated, what CPU registers and flags are and system calls are invoked on the stack. When you first start out, the code can seem impenetrable, but a little persistence will go a long way.

My advice is to pick an OS and stick with it - system calls differ between operating systems and there are various other little quirks in the way programs run that can confuse you. Search the Internet, buy some books and just keep playing around with it. One good tip that I have found works for me when I'm struggling is to write the program in C and use GDB to step through it at runtime to see what value certain registers have at a given time etc.

I'll try and post a couple of links for you to look at as soon as I can find them - I'm not at home atm and can't remember the links to the various sites I browse through.

As for an example of what assembly code actually looks like, the following is the assembly equivalent of the famous "Hello World" program from K&R, written for linux:

.data 

MyHelloString:
	.ascii "Hello World\n"

.text 

.globl _start 

_start:

		#Write() function to print the characters to stdout	
	movl $4, %eax
	movl $1, %ebx
	movl $MyHelloString, %ecx
	movl $12, %edx
	int $0x80

		#Exit() function to exit the program
	movl $1, %eax
	movl $0, %ebx
	int $0x80





What your seeing here is two functions: one to write the message to stdout and one to exit the program. the code first stores the sys code for each sys call into the EAX register, then stores the various required arguments into other registers and finally uses the interrupt operator to run the function.

Hopefully that's enough to get you interested! Will post some links asap B)

-n
Was This Post Helpful? 0
  • +
  • -

#3 Aaronugio   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-October 09

Re: What is Assembly?

Posted 29 January 2010 - 06:28 AM

Okay,that seems clear enough to me. Are the different forms of assembly always OS specific, or are there some that are specific to CPUs, and what are the different forms, and what is the purpose behind having all the different ones. I mean to say, what are the differences between x86 and SIMPLE and ASM and what all other forms are out there?

Also, aside from memory management, which doesn't seem like too big an ordeal to me, I love that kind of basic organization and such, what other commands does it handle? like audio transmission? graphics commands?

This post has been edited by Aaronugio: 29 January 2010 - 06:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 numeric   User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 77
  • Joined: 12-January 09

Re: What is Assembly?

Posted 29 January 2010 - 08:41 AM

I'm still learning assembly myself, so a bit of googling has been involved with finding your answers here :D

From my understanding, the architecture (that is, registers, flags etc) are specific to processor type - an intel processors architecture will be different from that of a SPARC processor, so the same code written for two different processors may differ greatly. How you use interrupts differs greatly between operating systems, with Linux being much simpler.

With regards to comparing x86 and ASM, I think your getting your terminology a little confused: ASM is a generic name for assembly language, where as x86 is a specific processor type. SIMPLE completely threw me and after a short google I have to confess that I'm still none the wiser as to what it actually is (wikipedia results returned a IM protocol and an algorithm) so someone else will have to help you out there :)

Different processors run in different ways, leading to different techniques used to give them instructions, which is why there are several different "types" of assembly language.

As for what you can do with assembly, your more limited by your sanity that what is actually possible - note the fact that in my earlier example it took 5 lines of code just to print a message to stdout. Complex tasks become pretty gruelling to program and debug, although there is nothing to stop you actually trying. I should probably mention that my main use for assembly is examining existing code, rather than building my own, so m experience is pretty limited.

To get an idea of what is possible, try looking up the sys calls for your operating system to see what they do. In linux, you can view a full list by running (note: tried in Ubuntu 9.04 32 bit):

cd /usr/include/asm
cat unistd_32.h



From here, just google anything that looks interesting. As I mentioned in my first post, you really can't get anything done in assembly until you have a half decent understanding of the stack and CPU registers. Once you understand those, you can start building simple programs and playing about with algorithms etc.

Hope this helps,

-n

EDIT: Just stumbled across a very nice short guide for assembly programming on linux using NASM, that also does a better job of explaining the differences between OS's and different syntax types such as Intel and AT&T than I did :) here

This post has been edited by numeric: 29 January 2010 - 08:51 AM

Was This Post Helpful? 0
  • +
  • -

#5 Aaronugio   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-October 09

Re: What is Assembly?

Posted 29 January 2010 - 12:37 PM

Thank you so much for your help and I'm getting on it right now!
Was This Post Helpful? 0
  • +
  • -

#6 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 556
  • View blog
  • Posts: 1,436
  • Joined: 22-August 09

Re: What is Assembly?

Posted 29 January 2010 - 01:00 PM

Once you have mastered writing applications in assembler, it is very easy to convert between machines as there are fundamental operations that need to be performed by all Von Neumann processors. Such operations arte load, store add subtract, left shift, right shift, algebraic operations etc. For example,

A = B + 2;



in C/C++ needs to be compiled into:

Load a value from the address that has been allocated the label B.
Add an immediate value of 2.
Store the result at the address that has been allocated the label A.

What most non-assembler programmers have the most difficuly with is thinking at this level.
Was This Post Helpful? 0
  • +
  • -

#7 Aaronugio   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 19-October 09

Re: What is Assembly?

Posted 15 February 2010 - 09:44 PM

Again thank you for your help, I'm wearing myself out, I'm learning java, working on my A+ certification, still mastering C++, trying to start learning lua, flash, taking two college classes, still in high school, trying to get a volunteer gig at the local hospital, and this on top, lolz, I'm living in beast mode, but i'm used to learning 4 or 5 things at a time, it actually helps keep my brain working on something, and helps me find correlations between languages and concepts, which helps me remember them, so, yeah. And Again, thanks so much for all the info, will try and catch up to you guys and hopefully will be helping out people on here someday in the near future.
Was This Post Helpful? 0
  • +
  • -

#8 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 556
  • View blog
  • Posts: 1,436
  • Joined: 22-August 09

Re: What is Assembly?

Posted 15 February 2010 - 10:58 PM

Quote

... helps me find correlations between languages and concepts ...


You are definitely travelling down the right path. Good luck with all you are doing and we look forward to your assistance in the future!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1