Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below


Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest! Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorAprz
    • CommentTimeMar 3rd 2009 edited
     permalink

    Bah, I really hate those simple simple simple programming mistakes. I bumped into one this morning a little bit after midnight (I don't know the time exactly though) and I didn't figure out what was wrong until 6:28 am... I spent many hours trying to figure this one out.

    Pretty much I was programming in x86 assembly for GAS (GNU Assembler) on Linux. I just learned how to open files, close files, write to them, read from them, retrieve argc, your program name from within the program, and retrieve argv[]. Anyhow, I decided to practice by writing my own version of cat in assembly. I then decided to write my own version of echo. I then tried writing something that would just ouput argc. For some reason, I couldn't get argc to output!

    .globl _start

    _start:
            movl    $4, %eax        # write system call
            movl    $1, %ebx        # STDOUT
            movl    0(%esp), %ecx   # argc
            movl    $1, %edx        # allocate one space
            int     $0x80           # interrupt

            movl    $1, %eax        # exit system call
            movl    $0, %ebx        # return 0
            int     $0x80           # interrupt

    This was suppose to simply return the number of arguments (argc). For example, if the binary for this was called test, executing ./test 1 2 3 should output 4 (it's including the program name). When I executed the program, it would return nothing. I was staring to get mad, browsed the Internet like crazy, poked at the code trying to figure out why it wasn't working. Spent hours and hours. I was gettng really mad because it's suppose to be this ultra simple thing.

    Anyhow, the answer was really simple, it was because I wasn't converting the number into ASCII . I found out when I decided to test it by not printing out the number, but have it return argc when the program exits and then just executing echo $?. It worked, I talked with a friend and that's when it all made sence, I wasn't converting into ASCII, which means all I had to do was add 48 to the number....If it has multiple digits, I already created an algorithm long ago when I was programming in Perl that would was really basic, it didn't use anything fancy, and I could do it in assembly without too much trouble I think, it would just look really really really scary. We can even discuss that algorithm later if you guys want to.

    Well, I am glad I am finally getting my hands dirty with assembly. C just isn't enough for what I want to do.

    I decided to post this little rant, I also know that a lot of you guys are web developers and programmers, and more likely have bumped into an issue like this before, I have, and probably have a story to tell so please share!

  1. Other Topics You Might Like
    What Object Oriented Programming(OOP) really means?
    Fry's Can Blame the Newspapers for Mistakes, But it Brings in Customers
    Why do customers waste our time? Ask stupid questions?
    Mlbz420 - You sound stupid and dumb!
    Why are customers so god damn stupid?
  2.  permalink
    *walks away*
    •  
      CommentAuthorSuzukiman
    • CommentTimeMar 4th 2009
     permalink
    seriously have to go over there and learn some of that.Looking for my head ............... yeah the eight valve one yeah ....
    •  
      CommentAuthorAyaHu
    • CommentTimeMar 4th 2009
     permalink
    This is what you put in your livejournal, not Frysforum. No one here is on your friendslist which means they probably dont care. Except your bro who loves you.Superhero!
    •  
      CommentAuthorasdf
    • CommentTimeMar 4th 2009
     permalink
    simple dude. use C  
     
    #include <stdio.h>  
    int main(int argc, char *argv[]) {  
    printf("%d\n", argc);  
    return 0;  
    }  
    •  
      CommentAuthorSuzukiman
    • CommentTimeMar 4th 2009
     permalink
    I care i need to learn it.Looking for my head ............... yeah the eight valve one yeah ....
    •  
      CommentAuthorAprz
    • CommentTimeMar 4th 2009
     permalink
    AyaHu, the direction I want to take this thread is to have developers such as yourself share stories on any mistake you've made that was really simple like this, but you spent hours or days trying to figure out what was wrong since you overlooked it.  
     
    For someone as educated as yourself, don't generalize either.  
     
    Asdf, I know C and I could have easily done it your way. In fact, if I wanted it to be done in x86 assembly still, I could have written it in C like what you have there and use GCC's -S flag like "gcc example.c -S" and then I would have hello.s without programming in assembly at all. The goal of this wasto practice using argc, argv[], read files, create them, and so on in x86 assembly for GAS.
    •  
      CommentAuthorsialer
    • CommentTimeMar 4th 2009
     permalink
    Aprz I appreciate what you've done and this is a free forum. Do not be discouraged by savages of the popular crowd. :face-smile::face-smile:Ignorance is bliss... but only to those who don't know better.
    •  
      CommentAuthorAprz
    • CommentTimeMar 4th 2009
     permalink
    sialer: Aprz I appreciate what you've done and this is a free forum. Do not be discouraged by savages of the popular crowd. :face-smile::face-smile:
     
    Can I add you to my friends list?
    •  
      CommentAuthorAyaHu
    • CommentTimeMar 4th 2009
     permalink
    My last mistake was not adding a semicolon to my as to make my loading movie play right. All I did to fix it was add the semicolon. I know. Powerful stuff.Superhero!
    •  
      CommentAuthorSasquatch
    • CommentTimeMar 4th 2009
     permalink
    I'm great with structure, but terrible with syntax.
    •  
      CommentAuthorasdf
    • CommentTimeMar 4th 2009 edited
     permalink
    your code looks like you want to print out argc from your stack. You might be passing the wrong address.  
     
    The only real programs ive written with x86 assembers are dos utils and viri.  
     
    int 80 linux syscall interface did not exists lol  
     
    I currently use asm for read/write control/data ports for controlling hardware, in bios, kernel, and userspace.