Advertisement
hackercademy

String

Dec 7th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     HelloWorldString:
  3.         .asciz "Hello World of Assembly!"
  4.     H3110:
  5.         .asciz "H3110"
  6. .bss
  7.  
  8.     .lcomm Destination, 100
  9.     .lcomm DestinationUsingRep, 100
  10.     .lcomm DestinationUsingStos, 100
  11.  
  12. .text
  13.  
  14.     .globl _start
  15.  
  16.     _start:
  17.         nop
  18.         # 1. Simple copying using movsb, movsw, movsl
  19.  
  20.         movl $HelloWorldString, %esi
  21.         movl $Destination, %edi
  22.  
  23.         movsb
  24.         movsw
  25.         movsl
  26.        
  27.         # 2. Setting / Clearing the DF flag
  28.  
  29.         std # set the DF flag
  30.         cld # clear the DF flag
  31.    
  32.         # 3. Using Rep
  33.        
  34.         movl $HelloWorldString, %esi
  35.         movl $DestinationUsingRep, %edi
  36.         movl $25, %ecx # set the string length in ECX
  37.         cld # clear the DF
  38.         rep movsb
  39.         std
  40.        
  41.         # 4. Loading string from memory into EAX register
  42.        
  43.         cld
  44.         leal HelloWorldString, %esi
  45.         lodsb
  46.         movb $0, %al
  47.        
  48.         dec %esi
  49.         lodsw
  50.         movw $0, %ax
  51.  
  52.         subl $2, %esi # Make ESI point back to the original string
  53.         lodsl
  54.  
  55.         # 5. Storing strings from EAX to memory
  56.  
  57.         leal DestinationUsingStos, %edi
  58.         stosb
  59.         stosw
  60.         stosl
  61.  
  62.         # 6. Comparing Strings
  63.        
  64.         cld
  65.         leal HelloWorldString, %esi
  66.         leal H3110, %edi
  67.         cmpsb
  68.        
  69.         dec %esi
  70.         dec %edi
  71.         cmpsw
  72.  
  73.         subl $2, %esi
  74.         subl $2, %edi
  75.         cmpsl
  76.  
  77.  
  78.         # The exit() routine
  79.  
  80.         movl $1, %eax
  81.         movl $10, %ebx
  82.         int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement