Guest User

Assembly DataTypes

a guest
Feb 28th, 2012
251
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #demo program to show how to use diffrent data types in assembly
  2.  
  3. .data
  4.         HelloWorld:
  5.                 .ascii "Hello World!"
  6.         ByteLocation:#8bits
  7.                 .byte 10
  8.         Int32:#32bits
  9.                 .int 2
  10.         Int16:#16bits interger or single 32bit floating point
  11.                 .short 3
  12.         float:
  13.                 .float 10.23
  14.         IntergerArray:
  15.                 .int 10,20,30,40,50
  16.  
  17. .bss
  18.         .comm LargeBuffer, 10000
  19.  
  20. .text
  21.         .globl _start
  22.  
  23.         _start:
  24.           nop # no operation flag
  25.         # 1 MOV immeditate value into the register
  26.         movl $10, %eax
  27.         # 2 Mov immediate value into memory location
  28.         movw $50, Int16 # note movw w=word 16bits
  29.         # 3 MOV data between registers
  30.         movl %eax, %ebx
  31.         # 4 mov data from (all.data is loaded into mem first)memory to register
  32.         movl Int32,%eax
  33.         # 5 MOV data from register to memory
  34.         movb $3, %al # using al as it's an 8bit register
  35.        movb %al, ByteLocation #moving %al to ByteLocation
  36.        # 6 Move data into an indexed memroy location
  37.        # Location is decided byBaseAddress(Offset,index,Datasize)
  38.        #Offset and index MUST be registers, Datasize can be a numerical value
  39.        movl $0, %ecx#offsert
  40.        movl $2, %edi#index (0,1,2) so pointint to 30
  41.        movl $22,IntergerArray(%ecx,%edi,4) #
  42.        # 7 Indirect addressing using registers
  43.        movl $Int32, %eax # address of int32 copied to eax
  44.        movl (%eax) , %ebx # using the addres of eax int32 is coptied to ebx(2)
  45.        # copying 9 into the memoery location %eax thats pointing to Int32
  46.        movl $9, (%eax)
  47.        # Exit the programmmmmmm
  48.        movl $1, %eax
  49.        movl $0, %ebx
  50.        int $0x80        
  51. # http://stackoverflow.com/questions/1898834/why-would-one-use-movl-1-eax-as-opposed-to-say-movb-1-eax
  52. # http://hackipedia.org/Books/Other/Programming%20From%20the%20Ground%20Up/ProgrammingGroundUp-1-0-booksize.pdf
RAW Paste Data