Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6797207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:34:52+00:00 2026-05-26T18:34:52+00:00

I’ve written a small assember program that gets and input file, an output file

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:34:52+00:00Added an answer on May 26, 2026 at 6:34 pm

    In “C” what you want to do is:

    if (strcmp(argv[3], "-a") == 0) {
       /* stuff here */
    }
    

    Since you’re working without the C standard library you have to create strcmp yourself. This isn’t too difficult as it amounts to:

    int strcmp(const char* str1, const char* str2) {
        while (*str1 && *str1 == *str2) { 
            str1++;
            str2++;
        }
        return *str1 - *str2;
    }
    

    Or in assembly:

    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
    

    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:

        # [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..
    

    Note that this assumes that you have a string to compare against placed in your data section like:

    .section .data 
    dasha: .asciz "-a"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.