hey everyone I think I'm enough experienced with C++ to go learning assembly language
I was googling for at least 2 months and found none good tutorials for it
does anyone know any good tutorial for assembly??
hey everyone I think I'm enough experienced with C++ to go learning assembly language
I was googling for at least 2 months and found none good tutorials for it
does anyone know any good tutorial for assembly??
Well C++ really doesn't prepare you for assembly language any better than any other language (basic logic, etc). You need to know the device you are coding for at a *very* low-level and you need to think in terms that are way lower than any high-level language will teach you. What chipset are you looking to code for?
hmmm interesting
well I'm looking for coding CPU (i7-920 and Intel mobile CPU)
well I've heard little about assembly coding
and I don't even know where to look for "short cuts of each CPU (as my father sad that each CPU has his own short cut to be faster)" --> but that later when I'll be expert in coding assembly
I would need really basic tutorial as I found this code:
________________________#VARIABLES: The registers have the following uses:
#
# %edi - Holds the index of the data item being examined
# %ebx - Largest data item found
# %eax - Current data item
#
# The following memory locations are used:
#
# data_items - contains the item data. A 0 is used
# to terminate the data
#
.section .data
data_items: #These are the data items
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
.section .text
.globl _start
_start:
movl $0, %edi # move 0 into the index register
movl data_items(,%edi,4), %eax # load the first byte of data
movl %eax, %ebx # since this is the first item, %eax is
# the biggest
start_loop: # start loop
cmpl $0, %eax # check to see if we’ve hit the end
je loop_exit
incl %edi # load next value
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax # compare values
jle start_loop # jump to loop beginning if the new
# one isn’t bigger
movl %eax, %ebx # move the value as the largest
jmp start_loop # jump to loop beginning
loop_exit:
# %ebx is the status code for the exit system call
# and it already has the maximum number
movl $1, %eax #1 is the exit() syscall
int $0x80
well problem is I don't understand what exactly is any of them:
%eax
%ebx
%ecx
%edx
%edi
%esi
%ebp
%esp
%eip
%eflags
what does each of them mean??
or how do I know exactly how to make such a program as that code is
I really need to know basics of assembly as I don't understand not even 10% of this code
I understand it only around 1 - 2%
Well I still maintain to get anything out of this you need to know the chipset at a low level since assembly language fiddles with the hardware registers directly. Here is a link to doing Intel assy language on Linux (my platform) not that it matters...see, for C, C++ etc to some extent the hardware doesn't matter but the OS does (Windows, Linux, etc). With assembler its the other way around: the OS doesn't matter since you are coding at a level beneath the OS but the hardware does since you are writing and reading directly from it. Anyhow there is no way of having "just a basic" set of assy know-how...you need to know the hardware well to do much and this is where the "short cuts" you refer to come in...
Introduction to Linux Intel Assembly Language
%e[a,b,c,d]x are general registers on an x86.
%e[d,s]i are index registers on an x86.
%e[b,s,i]p are pointer registers on an x86.
%eflags is the flags register on an x86.
This particular style of i386 assembly is, I believe, AT&T style, though I cannot remember off hand.
Looks like this is a "simple" code snippet that copies an array to another location.
There are hundreds of free, on-line x86 assembly reference materials out there. If you need more help, you can ask, but there is really no formal location for Assembly on this forum anymore.
EDIT: One thing I left off: This is using the extended version of the registers (i.e. e ax in place of the native 16-bit ax register).
Last edited by Kennedy; 01-26-2010 at 05:02 PM.
Yeah the last "formal" assembly stuff I read was the Peter Norton book on Intel assembly, seems like a lifetime ago....after doing 65xx assembly I HATED Intel and quit after a few projects...hated the segmented memory model for one thing...
ok I'm familiar with pointers
now my dad sad that pointer in C++ sounds like register in assembly (he only coded assembly 15 years ago)
now I'm confused what's different betwin register and pointer
and what exactly is "flags"?
No register is not pointers. Pointers point to a specific location in a systems memory (IE RAM). Registers can be seen as small locations of memory located on a CPU, which can hold say an index, a small piece of memory (1 byte or something, very cpu dependant). The registers are extremly few in compared to the amount of system memory. You also have registers that holds memory-locations (stack point registers for instance). Other registers keep track of where in the system memory your next piece of instruction is located (often called PC register or Program Counter register).
The flag register typically holds information when some kind of arithmetic operation is performed. A compare operation for instance can be done by doing A - B, and if the result is 0 a "zero-bit" may be set in the flags register (again depends on cpu). Same if you perform A + B, the flag register can contain info about overflows and stuff like that.
Im sure a complex CPU contains alot more, ive only done assembly programming on microprocessors so say your average intel cpu in a home-computer is much more complex.
Edit again: In my opinion its good to have a basic grasp of the buildingblocks of a CPU (for instance registers, ALU, FPU and a bunch of other stuff) before trying to do assembly. It will save you some headache and it will allow you to understand the CPU better.
Last edited by Shakti; 01-26-2010 at 06:03 PM.
So, I typed up this really good message last night for this post. I gave you lots of info. I gave you a very quick, concise insight to Assembly. I typed it all while holding my 1-yr old. She was playing nicely with a rubber puzzle. She slung the puzzle at the keyboard and BAM! no more message.
The brunt of it was this: Here is a good reference manual that will tell you everything I attempted to tell you.
The "pointer registers" are like pointers in the sense that they are memory locations that hold the address of another location. However, they cannot be created, I believe every process has the same predefined set of registers. This may be because they are actual locations in the CPU when the process is active. (??)
Last edited by MK27; 01-27-2010 at 09:50 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Yes, as I stated before, these are REGISTERS ON THE x86. There are a whole host of other registers too, listed in the link I provided. And there is a janormous command set that goes with these processors. It is almost like these processors have been mainstream for a really long time.
every CPU has a predefined set of registers (at least every processor i have worked with, which doesnt say alot). This is because a register is an actual location on the cpu, and is connected to the internal databus within the cpu (again cant confirm this is the case with intel but every cpu i have worked with this has been the case).
ok I'm slowly making progress in assembly
now I don't understand what's the difference between this 2 tutorials
this one can be assembled and run with:section .text
global _start:
_start:
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,lengt
int 80h
mov eax,1
mov ebx,0
int 80h
section .data
hello: db "hello world", 0x0a
lengt: equ 13
nasm -f elf filename.asm ; makes filename.o
ld -o newfilename filename.o ; makes from filename.o --> newfilename
./newfilename ; excecude the written program
and this one
this one can be assembled and run with:#PURPOSE: Simple program that exits and returns a
# status code back to the Linux kernel
#
#INPUT: none
#
#OUTPUT: returns a status code. This can be viewed
# by typing
#
# echo $?
#
# after running the program
#
#VARIABLES:
# %eax holds the system call number
# %ebx holds the return status
#
.section .data
.section .text
.globl _start
_start:
movl $1, %eax # this is the linux kernel command
# number (system call) for exiting
# a program
movl $5, %ebx # this is the status number we will
# return to the operating system.
# Change this around and it will
# return different things to
# echo $?
int $0x80 # this wakes up the kernel to run
# the exit command
as filename.s -o newfilename.o ; makes newfilename.o // object file (almost CPU language)
ld newfilename.o -o newfilename1 ; ld = linker makes newfilename1 //it's excecudable for linux
./newfilename1 ; excecude the written program
When learning assembly for the first time you're not learning the registers or the instructions. All of that can be easily accomplished with reference cards.
You should be learning how memory works and how memory works compared to HLLs, how to work in hex and binary, how to use the stack, the difference between big and little endian, how to plan to write code, how to document code efficiently, how to optimize code for memory or speed or find a happy medium or even learning how to figure out which way to go with your project at hand.
Learning assembly is about understanding how things work, if you take the approach that people do with HLLs and just learn a general flow of a program and then learn the instruction set you might as well not even bother unless all you wish to accomplish is an ability to better utilize debuggers.
Such as your last question, the first example is in intel style assembly syntax which nasm recognizes. The second example is AT&T style assembly syntax which is recognized by the gas assembler and gcc uses gas.
If you ask which one to learn you've obviously missed the point of my entire post.
As to your original question. Jeff duntemanns put out a few good books for sale.
There's the Art of Assembly which is a free online beginners book.
There's PC Assembly by Dr paul carter which is a free online book that leans more towards integrating x86 assembly with C.
There's a free online beginner tutorial that I found to be well written on x86 and NASM on another forum ->Let's learn assembly! - Assembly
Programming from the ground up is a good book that has free copies floating around on the internet.