Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   Assembly, Assembler? (http://www.programmingforums.org/showthread.php?t=9624)

v0id May 2nd, 2006 11:08 AM

Assembly, Assembler?
 
Hi everybody!
I want to learn Assembly, but it seems to be hard to find something about it.
I have programmed C, C++ and Python, but i have heard that Assembly is kinda good for understanding different stuff.
So..

Can someone tell me about Assembly and/or Assembler?
What programs there can be used for it?
Some basic, for an example a "Hello World"-program?
How I start?
Is it a good thing to learn Assembly?

I have allready looked around on the net, but i din't find something.
(http://www.programmingforums.org/for...ead.php?t=5405)

Hope someone can help!

(Sorry my english..)

DaWei May 2nd, 2006 11:43 AM

Microprocessor operations are driven by the application of hardware gating and clocking signals which apply binary logic levels to various devices. Some of these devices are memory elements outside the cpu, some are memory elements inside the cpu (registers), some perform binary logic and arithmetic operations. There are others. These signals are controlled by binary signal states that have as their source (primarily) the "instructions" provided by those who are programming the device. The physical arrangement of the wiring of the bits will determine what causes two things to be added in one processor, versus what states will cause the same operation in another processor. These are the "machine instructions." Assembly language is, essentially, a set of mnemonics that represent these codes. There is very little abstraction other than being able to say, "LD A, 7", versus "0x3E 0x07". This situation can be mitigated somewhat by macro assemblers and so-called "high-level" assemblers. Despite exceptions and caveats, one is essentially dealing with the nuts and bolts.

Narue May 2nd, 2006 11:47 AM

>Can someone tell me about Assembly and/or Assembler?
Assembly is a language based on mnemonic names for machine instructions. It's as low as you can get without using a hex editor to manually write opcodes. An assembler is a program that translates the mnemonic names and other directives into machine code.

>What programs there can be used for it?
It depends on what you're doing. Some assemblers can output executable programs directly, so all you would need is the assembler and a debugger. A somewhat more flexible approach uses assemblers that output object files, in which case you need the assembler, a debugger, and a linker. OllyDbg is a good debugger, and I usually use the linker that comes with GCC.

>Some basic, for an example a "Hello World"-program?
Here's one in FASM that assembles right to an executable:
:

format PE console
entry start

include 'C:\fasmw\include\win32a.inc'

;======================================
section '.data' data readable writeable
;======================================

hello db 'Hello, world!',10,0

;=======================================
section '.code' code readable executable
;=======================================

start:
        cinvoke        printf,hello
        invoke        ExitProcess,0

;=====================================
section '.import' import data readable
;=====================================

library kernel,'kernel32.dll',\
        msvcrt,'msvcrt.dll'

import kernel,\
      ExitProcess,'ExitProcess'

import msvcrt,\
      printf,'printf'

There are no instructions in that, it's all directives and macros. So hello world only gives you a taste of how much framework an assembler requires, and how easy I/O is. Here's the same program in NASM, but it assembles to an object file and needs to be linked:
:

;==============
[section .data]
;==============

hello db 'Hello, world!',10,0

;==============
[section .text]
;==============

global _main
extern _printf

_main:
        push        hello
        call        _printf
        add        esp,4
        mov        eax,0
        ret

This is smaller because it relies on the linker to do the import stuff that FASM was doing. NASM also doesn't come with a convenient include file with macros, so I did manually what cinvoke was doing behind the scenes (the C calling convention: arguments are pushed in reverse order, and the stack is restored after the call). Also, instead of calling ExitProcess, this NASM program is a direct translation of the following C program (which is why eax is set to 0 before returning):
:

#include <stdio.h>

int main ( void )
{
  printf ( "Hello, world!\n" );
  return 0;
}

FASM can also output object files just like NASM:
:

format MS COFF

include 'C:\fasmw\include\win32a.inc'

;===================
section '.data' data
;===================

hello db 'Hello, world!',10,0

;===================
section '.code' code
;===================

public _main
extrn _printf

_main:
        cinvoke        _printf,hello
        mov        eax,0
        ret

>How I start?
Get an assembler, find a reference, and start writing programs. Just like any language. Of the assemblers out there, the most popular are MASM, NASM, and FASM. FASM is a good combination of flexibility and simplicity, but NASM is easier to learn in my opinion. MASM has too many inconsistencies to be a good first assembler, but it's powerful. You might also look into HLA, if you want to ease into assembly rather than jump right in.

>Is it a good thing to learn Assembly?
Yes.

v0id May 3rd, 2006 7:34 AM

Hmm?
 
Thanks both of you.
But i don't really understand it.
Can someone please give me a step-to-step-Guide?

Linker-program: Which one?
Assembler-program: Which one?
Debugger-program: Which one?
--
MASM is..? Shall i download it?
NASM is..? Shall i download it?
FASM is..? Shall i download it?
HLA is..? Shall i download it?
... And if you have some links, I'll be pleased

I'm sorry, but i just really want to learn it!

DaWei May 3rd, 2006 8:02 AM

This is a personal viewpoint. Check Narue's avatar to see if there's agreement. If you don't know what constitutes a typical, basic 'computer', memory, the cpu with its registers, alu, and such, you need to go there first. No need to worry initially about such things as MMUs, cache, and the like. Just the basic operational elements and how they interact.

Narue May 3rd, 2006 8:17 AM

>But i don't really understand it.
You're not expected to understand everything immediately.

>Can someone please give me a step-to-step-Guide?
I'm working on one, but it's not ready yet.

>Linker-program: Which one?
>Assembler-program: Which one?
>Debugger-program: Which one?
That's like asking someone which layout style to use. It's 100% personal preference if you're not forced to use something. If you don't have a preference, try them all and develop one.

>... And if you have some links, I'll be pleased
www.google.com

v0id May 3rd, 2006 8:21 AM

DaWei >
I don't actually know how a computer works with CPU, Memory and all that stuff.
I actually thought that i could learn something about it, throught Assembly.
But I was wrong?
Shall i read about CPU, Memory etc. before i'm going to learn Assembly?

Narue >
>> I'm working on one, but it's not ready yet.
It will be nice!



*I din't know ASM was so damn hard! But someday, I will learn it!*

Narue May 3rd, 2006 9:57 AM

>I actually thought that i could learn something about it, throught Assembly.
You can.

>Shall i read about CPU, Memory etc. before i'm going to learn Assembly?
If you start with 32-bit flat mode, there's not much to it. The tricky stuff is under a segmented architecture. Modern x86 assembly doesn't require intimiate knowledge of the hardware to get started.

>I din't know ASM was so damn hard!
Assembly is actually easier to learn than any high level language I can think of. You just need to shift your thinking, and that's where most people stumble.

v0id May 3rd, 2006 10:09 AM

It's maybe not hard to learn the language, but it's hard to getting started with all the debuggers, linkers etc.

A hurry question:
Is Assembly just for extensions to C and other lanuage, or can it make Applications by itself? And can it make bigger applications or just some small stuff, like calulate?

(I'm sorry that i ask so much (I don't normally do), but I just can't find anything of ASM)

DaWei May 3rd, 2006 10:11 AM

It is a matter of perspective. Would you rebuild your carburetor to learn how carburetors work, or would you research carburetors before you rebuilt it? You could wind up in the same place, either way. Narue's point, "you just need to shift your thinking", is the key. There's very little abstraction. Your instructions are controlling the hardware operations that perform logical and arithmetic operations almost directly. I can conceive of your approach, but I haven't lived it. I was given a handful of devices and a stack of spec sheets, told I now had a microprocessor in my possession, and I needed to see how it did trying to control a motor (it failed abysmally). On the other hand, I used Fortran to design some filters without knowing or caring about computers beyond the syntactical and semantic requirements. It was harder to punch the cards than write the program.


All times are GMT -5. The time now is 4:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC