Results 1 to 4 of 4

Thread: linux vs assembly

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    119

    linux vs assembly

    Hello.. pals


    i just wanna learn assembly.so does linux provide any assembler with it.i use RH 7.1.Help plz.

  2. #2
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,534
    depends if u installed it...

    else get one..

    there are a lot of assemblers 4 linux
    ASCII stupid question, get a stupid ANSI.
    When in Russia, pet a PETSCII.

    Get your ass over to SLAYRadio the best station for C64 Remixes !

  3. #3
    NASM is probably the most popular

    get it here - www.web-sites.co.uk/nasm/

  4. #4
    Code:
    Linux does have/provide support of assembly programming.
    
    'gas' is generic provided assembler. It uses AT&T syntax
    'nasm' also works for RH7.1  and it uses Intel syntax
    both of these applications are on the linux distribution 
    disk.
    
    
    Here is an example of the two forms to show the same functionality
    example is taken from Assembly Language Step-by-Step by J.Duntemann
    
    
    AT&T                      ||     Intel
                              || 
    movl -4(%ebx), %eax       ||     mov dword eax,[ebx-4]
                              ||
    movb 28(%ebx,%edi), %eax  ||     mov byte eax,[ebx+edi+28]
    
    
    IMO the Intel is easier to read.
    
    ========================================
    
    
    There is a high level kind of assembler programming and a lower
    level, kernel mode assembler. The higher level is a hybrid of 
    C and assembly, (CASM). The lower form is using kernel sys calls
    via interupt 80h (int 80h).
    
    J.Duntemann's book is very basic introduction level programming and
    he uses the CASM style of programmming. Just forgetting stack frame
    creation and destruction for a minute, here is how you would write
    a text message to the standard output (1) i.e. screen
    
    [section .text]
    
    extern puts  ; clib function
    global main  ; entry point for linker
    
    main:
    
        ;                   ; create stack frame code
    
        push dword message  ; push address of msg on stack 
        call puts           ; function call
        add esp, 4          ; realign stack
    
        ;                   ; destroy stack frame code
    
    [section .data]
    
    message: db "hello",0x0A,0x00    
    
    
    
    ========================================
    
    Now a more advanced style (not covered by Dunteman) int 80h type
    goes like this.
    
    
    PZ's simple int80h demo
    read a file and output it to standard output i.e the screen
    compile/link/execute
    --------------------
    nasm -f elf read_write01.asm
    gcc read_write01.o -o demo01
    ./demo01 read_write01.asm
    ------------------ cut from here ---------------------------------
    
    BITS 32
    GLOBAL _start
    SECTION .text
    
    O_RDONLY  EQU 0
    sys_close EQU 1
    sys_read  EQU 3
    sys_write EQU 4
    sys_open  EQU 5
    std_oput  EQU 1
    
    
    _start:   mov ebp,esp
    	  mov eax,[ebp]      ; argc
              mov [argc],eax     ; copy the address value to variable
    
              lea ebp,[esp+4]
              mov eax,[ebp]      ; argv0
              mov[argv0],eax
    
              lea ebp,[esp+8]
              mov eax,[ebp]      ; argv1 
              mov [argv1],eax
    
    Openit:   mov eax,sys_open   ; open
              mov ebx,[argv1]    ; path in argv[1] of command line
              mov ecx, O_RDONLY  ; read only
              mov edx, 0         ; permission mode not relevant to read
              int 0x80
    
              mov[filedesc],eax  ; save the returned file descriptor
    
    printfd:  mov eax,sys_write  ; write
    	  mov ebx,std_oput   ; standard output           
              mov ecx,filedesc   ; print the file descriptor
              mov edx,4          ; it is 4 bytes long
              int 0x80
    
    readit:   mov eax,sys_read   ; read
              mov ebx,[filedesc] ; our file, just opened
              mov ecx,storage    ; scratchpad area
              mov edx,1024      
              int 0x80
    
    printit:  mov eax,sys_write  ; write
              mov ebx,std_oput   ; standard output
              mov ecx,storage    ; output what was read in from the file
              mov edx,1024   
              int 0x80
    
    finish:   mov eax,sys_close
              int 0x80
    
    SECTION  .bss
    argc      RESD 1
    argv0     RESD 1
    argv1     RESD 1
    filedesc  RESD 1
    storage   RESB 1024
    
    ----------------------- finish cut -------------------------
    
    
    ==========================================
    
    You can also mix and match CASM with int80h, which is sometimes easier
    if you are a bit lazy. 
    
    Another thing that is permisable is to use inline assembler embedded into
    C code. Infact this is how the Linux kernel is constructed.
    
    example:
    
    static inline void set_in_cr4(unsigned long mask)
    {
       mmu_cr4_features |= mask;
       __asm__("movl %%cr4,%%,%%eax\n\t"
         "orl %0,%%eax\n\t"
         "movl %%eax,%%cr4\n"
         : : "irg" (mask)
         :"ax");
    }
    
    
    really nice looking this inline AT&T assmbler with C, ey?
    Next lesson how to grab ring-0 with buffer overflows *lol*
    
    
    PZ
    
    p.s.  remember how when kids advance from baby languages like BASIC
          to Pascal, Fortran, C/C++ etc  they are told to forget all about
          GOTO  cus now we are learning structured programming, well 
          once you get back to serious system level programming you 
          start using GOTO again. *grin*  The linux kernel consists of
          about 1 in every 80 lines has a GOTO.
    
          C-ASM inline is dirty powerful programming, who cares if we
          cheat.

Posting Permissions

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