Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- assembler- Pass parameter and use it in program
- movl 16(%ebp),%eax
- .section .data
- #######PROGRAM CODE###
- .section .text
- #STACK POSITIONS
- .equ ST_SIZE_RESERVE, 8
- .equ ST_FD_IN, 0
- .equ ST_FD_OUT, 4
- .equ ST_ARGC, 8 #Number of arguments
- .equ ST_ARGV_0, 12 #Name of program
- .equ ST_ARGV_1, 16 #Input file name
- .equ ST_ARGV_2, 20 #Output file name
- .equ ST_ARGV_3, 24 #-a or -l or nothing
- .equ ST_EXIT_CODE, 28 #Exit code
- .globl _start
- _start:
- ###INITIALIZE PROGRAM###
- subl $ST_SIZE_RESERVE, %esp #Allocate space for our pointers on the stack
- movl %esp, %ebp
- ### Set standard error code 0
- movl $0, %ebx
- movl %ebx, ST_EXIT_CODE(%ebp)
- movl ST_ARGV_3(%ebp),%eax #eax contains now the alternative paramter
- if (strcmp(argv[3], "-a") == 0) {
- /* stuff here */
- }
- int strcmp(const char* str1, const char* str2) {
- while (*str1 && *str1 == *str2) {
- str1++;
- str2++;
- }
- return *str1 - *str2;
- }
- strcmp:
- push %ebp
- mov %esp, %ebp
- movl 0x8(%ebp), %esi # str1
- movl 0xc(%ebp), %edi # str2
- 1:
- movb (%esi), %al
- or %al, %al # *str1 zero?
- jz 2f
- movb (%edi), %ah
- cmp %ah, %al # equal to *str2?
- jne 2f
- # move to next character
- inc %esi
- inc %edi
- jmp 1b
- 2:
- # result is difference between the two characters compared
- movb (%esi), %al
- subb (%edi), %al
- movsx %al, %eax # Sign-extend to 32-bits
- pop %ebp
- ret
- # [snip]
- movl ST_ARGV_3(%ebp),%eax #eax contains now the alternative paramter
- push %eax # first argument
- pushl $dasha # second argument "-a"
- call strcmp # compare strings
- add $8, %esp # pop arguments
- cmpl $0, %eax # Strings equal?
- je strings_are_equal # Subtitute your own logic here
- jmp strings_are_not_equal # and here..
- .section .data
- dasha: .asciz "-a"
Add Comment
Please, Sign In to add comment