Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (37 sloc) 0.942 kb
6c95218 @dharmatech more md
authored
1
2 # Call the strcat glibc C function
3
4 # C
5
6 ```c
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11
12 int main ( int argc , char * argv[] )
13 {
14 char * data = malloc( 1000 ) ;
15
16 data[0] = '\0' ;
17
18 strcat( data , argv[1] ) ;
19 strcat( data , argv[2] ) ;
20
21 printf( "%s\n" , data ) ;
22
23 return 0 ;
24 }
25 ```
26
27 # Assembly
28
29 ```s
30
31 .include "utils.s"
32
33 global_text main
34
35 prepare_stack
36
37 .set offset , 0
38
39 stack_allocate ARGV , 8
40 stack_allocate DATA , 8
41
42 mov %rsi , ARGV(%rbp)
43
44 mov $1000 , %rdi
45
46 call malloc ; mov %rax , DATA(%rbp)
47
48 set1 $0 , DATA , 0
49
50 mov DATA(%rbp) , %rdi ; ref8 ARGV , 1 , %rsi ; call strcat
51 mov DATA(%rbp) , %rdi ; ref8 ARGV , 2 , %rsi ; call strcat
52
53 print_string DATA(%rbp)
54 print_nl
55
56 return_integer $0
a5b0fff @dharmatech minor tweaks
authored
57 ```
6c95218 @dharmatech more md
authored
58
59 # Assemble and run
60
61 $ gcc strcat.s -lm && ./a.out abc def
62 abcdef
Something went wrong with that request. Please try again.