Contribute  :  Web Resources  :  Past Polls  :  Site Statistics  :  Downloads  :  Forum  
    BiW ReversingThe challenge is yours    
 Welcome to BiW Reversing
 Monday, October 25 2021 @ 08:55 AM CEST

using Gas to assemble with intel syntax

   

CodingLevel : newbie

OS : linux
Language : asm

you might have read my earlier article on using gcc with inlined intel syntax
continuing with that article i now present you an article that shows how to
do assembly with gas using Intel Syntax so all those masm programmers wont be
lost in the maze of % $ + reversed dest,src At&T syntax and GAS




.intel_syntax #noprefix stick this directive on top

.data

foo: .asciz "hello from GAS using intel_syntax\n" #notice : after foo ? A label needs that colon in GAS

faa: .asciz "the length of the string foo is 0x%x ok or in decimal %d long\n"

#this .bss is the one you have to use instead of .data? (you masmers)

.bss
.lcomm len,4 #equivalent to len dd ?

.text
.global start #some requirement that kills lot of linker warnings so stick this here

#lets play our game as usual  free of % $ + reversed whatever superior syntax crap

start:
        push    offset foo
        call    strlen
        add     esp,4
        mov     len,eax
        push    len
        push    len
        push    offset faa
        call    printf
        add     esp,0xc
        push    offset foo
        call    printf
        add     esp,4
        push    1
        call    exit


#no end start directive here

ok now we assemble and link this like this

i created a .sh file so that i dont have to type or hit arrow keys

the contents are as below


cat make.sh
as -o testas.o testas.s
ld -o testas testas.o -defsym _start=start --dynamic-linker=/lib/ld-linux.so.2 /usr/lib/libc.so -s

thanks goes to mammon for the linker commandline the defsym symbol=name
argument is to override a linker warning that looks for _start symbol
-s = strip those symbol info that gets embedded

as doesnt accept comments or i dont know how to make it accept :)

edit ok i found out the comment is denoted by # symbol so it assembles
without warning i updated the code to reflect it
also i added stack cleanup code so the ht display below will different from the code above

ok run that
./make-sh

now that we have assembled and linked lets run this baby and see if it runs


./testas
the length of the string foo is 0x22 ok or in decimal 34 long
hello from GAS using intel_syntax

runs nice

lets disassemble this with ht and see how it looks :)

  ....... ! ;******************************************************************                   
  ....... ! ;  section 9 <.text>                                                                  
  ....... ! ;  virtual address  080481f4  virtual size   00000036                                 
  ....... ! ;  file offset      000001f4  file size      00000036                                 
  ....... ! ;******************************************************************                   
  ....... !                                                                                       
  ....... ! ;****************************                                                         
  ....... ! ;  executable entry point                                                             
  ....... ! ;****************************                                                         
  ....... ! entrypoint:                                                                           
  ....... !   push        strz_hello_from_GAS_using_intel_sy_804922c                              
  80481f9 !   call        strlen                                                                  
  80481fe !   mov         [?data_8049348], eax                                                    
  8048203 !   push        dword ptr [?data_8049348]                                               
  8048209 !   push        dword ptr [?data_8049348]                                               
  804820f !   push        strz_the_length_of_the_string_foo__804924f                              
  8048214 !   call        printf                                                                  
  8048219 !   push        strz_hello_from_GAS_using_intel_sy_804922c                              
  804821e !   call        printf                                                                  
  8048223 !   push        1                                                                       
  8048225 !   call        exit                                                                    
  804822a                                                                                         
  .......   ;******************************************************************                   
  .......   ;  end of section <.text>                                                             
  .......   ;******************************************************************                   
Source can be found here

thats all for now happy coding with intel syntax

stingduk




What's Related

Story Options

using Gas to assemble with intel syntax | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
 Copyright © 2021 BiW Reversing
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.83 seconds