assembly tut --> help

This is a discussion on assembly tut --> help within the Linux Programming forums, part of the Platform Specific Boards category; hey everyone I think I'm enough experienced with C++ to go learning assembly language I was googling for at least ...

  1. #1
    beginner for now
    Join Date
    Oct 2009
    Posts
    35

    assembly tut --> help

    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??

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    beginner for now
    Join Date
    Oct 2009
    Posts
    35
    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%

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    %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.

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  7. #7
    beginner for now
    Join Date
    Oct 2009
    Posts
    35
    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"?

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,209
    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.

  9. #9
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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.

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by military genius View Post
    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"?
    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

  11. #11
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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.

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    1,209
    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).

  13. #13
    beginner for now
    Join Date
    Oct 2009
    Posts
    35
    ok I'm slowly making progress in assembly

    now I don't understand what's the difference between this 2 tutorials
    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
    this one can be assembled and run with:

    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
    #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
    this one can be assembled and run with:

    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

  14. #14
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 01:12 PM
  2. C to assembly interface
    By Roaring_Tiger in forum C Programming
    Replies: 4
    Last Post: 02-04-2005, 03:51 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 02:11 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21