I’ve written a small assember program that gets and input file, an output file and an alternative parameter (either -a or -l).
Now I want to distinguis in the program if the user has passed a -a or -l. I know I can pass the parameter into, e.g %eax like follows:
movl 16(%ebp),%eax
But now I don’t know how to compare %eax with -a or with -l to check what parameter was passed.
The program runs on a 32-bit Linux OS.
Can anyone give me a hint please?
Thanks in advance,
enne
EDIT: I have a x86-processor. Here are some relevant parts of the code
.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
In “C” what you want to do is:
Since you’re working without the C standard library you have to create
strcmpyourself. This isn’t too difficult as it amounts to:Or in assembly:
Of course if you’re not actually using the computed difference between the strings (it’s useful for sorting) you can simplify the procedure slightly.
And using it:
Note that this assumes that you have a string to compare against placed in your data section like: