Results 1 to 4 of 4

Thread: Discussion: Programming from the Ground Up

  1. #1
    Join Date
    Nov 2005
    Beans
    Hidden!
    Distro
    Ubuntu 6.06

    Question Discussion: Programming from the Ground Up

    mkay, so I know a few language, but I've never messed with assembly before. So I decided to learn. To do so I'm reading "Programming from the Gound Up" which can be found here.

    Right off the bat, I'm having trouble... I entered the first program into gedit and saved it as exit.s, assembled and linked it. Ran it and it return 0 as expected.

    I then edited the line:
    Code:
     movl $0, %ebx
    to:
    Code:
     movl $200, %ebx
    assembled and linked, ran it and it still returns 0?

    exit.s looks like this now:
    Code:
    .section .data
    
    .section .text
    .globl _start
    _start:
    movl $1, %eax
    movl $200, %ebx
    init $0x80
    Im running i686 kernel on a P4 M, any help?

  2. #2
    Join Date
    May 2006
    Beans
    1,790

    Re: Discussion: Programming from the Ground Up

    Quote Originally Posted by elemental666
    mkay, so I know a few language, but I've never messed with assembly before. So I decided to learn. To do so I'm reading "Programming from the Gound Up" which can be found here.

    Right off the bat, I'm having trouble... I entered the first program into gedit and saved it as exit.s, assembled and linked it. Ran it and it return 0 as expected.

    I then edited the line:
    Code:
     movl $0, %ebx
    to:
    Code:
     movl $200, %ebx
    assembled and linked, ran it and it still returns 0?

    exit.s looks like this now:
    Code:
    .section .data
    
    .section .text
    .globl _start
    _start:
    movl $1, %eax
    movl $200, %ebx
    init $0x80
    Im running i686 kernel on a P4 M, any help?
    For what it's worth, when I do the same, I get 200, as expected. Try all the steps again: modify the file, save the file in the editor, assemble it, link it. Maybe there was an error message you didn't catch, because "init" above should be "int".

  3. #3
    Join Date
    Nov 2005
    Beans
    Hidden!
    Distro
    Ubuntu 6.06

    Re: Discussion: Programming from the Ground Up

    the actual code said int, I posted from a different machine. I dunno what the deal was, but I just tried it and it worked. crazy

  4. #4
    Join Date
    Jul 2005
    Location
    Northern CA
    Beans
    657
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Discussion: Programming from the Ground Up

    One of the problems I have with that book is that it treats assembly lanugage separately. If you wish to integrate your assembly language functions with C/C++, the standard in the 32-bit x86 world is to place the return value in eax. For example, a program that simply returns a value would be
    Code:
            .text
            .globl  main
    
    main:   pushl   %ebp        # save caller's base pointer
            movl    %esp, %ebp  # establish our base pointer
    
            movl    $0, %eax    # return 0 to caller
            movl    %ebp, %esp  # restore stack pointer
            popl    %ebp        # restore caller's base pointer
            ret                 # back to caller
    which is essentially equivalent to
    Code:
    int main() {
       return 0;
    }
    You can assemble this with
    Code:
    as --gstabs -o doNothing.o doNothing.s
    and link it with the necessary C libraries with
    Code:
    gcc -o doNothing doNothing.o
    The --gstabs assembler option allows you to use symbols in gdb.

    Using gcc for the linking phase instead of ld automatically links in the C libraries. If you use ld, you need to explicitly list all the libraries.
    Intel i7-920; Nvidia GT 220, 1GB; MSI X58 Pro-E; 6GB DDR; 64-bit mode.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •