Advertisement
hackercademy

Untitled

Dec 4th, 2013
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Demo program to show how to use Data types and MOVx instructions
  2.  
  3. .data
  4.  
  5.     HelloWorld:
  6.         .ascii "Hello World!"
  7.  
  8.     ByteLocation:
  9.         .byte 10
  10.  
  11.     Int32:
  12.         .int 2
  13.     Int16:
  14.         .short 3
  15.     Float:
  16.         .float 10.23
  17.  
  18.     IntegerArray:
  19.         .int 10,20,30,40,50
  20.  
  21.    
  22. .bss
  23.     .comm LargeBuffer, 10000
  24.  
  25. .text
  26.  
  27.     .globl _start
  28.  
  29.     _start:
  30.        
  31.        
  32.        
  33.         # 1. MOV immediate value into register
  34.  
  35.         movl $10, %eax
  36.  
  37.         # 2. MOV immediate value into memory location
  38.  
  39.         movw $50, Int16
  40.        
  41.         # 3. MOV data between registers
  42.  
  43.         movl %eax, %ebx
  44.  
  45.  
  46.         # 4. MOV data from memory to register
  47.  
  48.         movl Int32, %eax
  49.  
  50.         # 5. MOV data from register to memory
  51.  
  52.         movb $3, %al
  53.         movb %al, ByteLocation
  54.  
  55.         # 6. MOV data into an indexed memory location
  56.         # Location is decided by BaseAddress(Offset, Index, DataSize)
  57.         # Offset and Index must be registers, Datasize can be a numerical value
  58.  
  59.         movl $0, %ecx
  60.         movl $2, %edi
  61.         movl $22, IntegerArray(%ecx,%edi , 4)
  62.  
  63.         # 7. Indirect addressing using registers
  64.  
  65.         movl $Int32, %eax
  66.         movl (%eax), %ebx
  67.  
  68.         movl $9, (%eax)
  69.  
  70.    
  71.  
  72.         # Exit syscall to exit the program
  73.  
  74.         movl $1, %eax
  75.         movl $0, %ebx
  76.         int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement