Check this little assingment of arithmatic operation...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Check this little assingment of arithmatic operation...

  1. #1
    Join Date
    Nov 2004
    Posts
    20

    Check this little assingment of arithmatic operation...

    The assignment is:
    "Consider the following pseudo-code and write the corresponding assembly code for it.
    Note: There is more credit for a shorter code.

    Code:
    if (al>bl) AND (bl>cl){
         CX=1
    }
    and I've write the code:

    Code:
    [org 0x0100]
              mov al, 7
              mov bl, 3
              mov cl, 5
              cmp al, bl
              ja L1
              jmp done
    L1:       cmp bl, cl
              jb done
              mov cx, 1
    done:     mov 0x4c00
              int 0x21
    Now please do it more shorter if possible, I'll much thankful to you.


    Mood.

  2. #2
    Join Date
    Feb 2004
    Location
    Helsinki, Finland
    Posts
    31

    Re: Check this little assingment of arithmatic operation...

    There isn't a lot of sense in reducing the number of instructions, since small size doesn't necessarily equal fastest code. Speed is kind of the point with asm nowadays, unless we're talking about extremely memory-limited microcontrollers (but these don't use the x86 instruction set).

    That said, the comparison stage could be a bit shorter:
    Code:
    	cmp	bl,al
    	jae	done
    	cmp	cl,bl
    	jae	done
    	mov	cx,1
    done:
    A couple of issues with your original code: Shouldn't it be "jbe done" instead of "jb done"? And what's "mov 0x4c00"? Missing an operand?

  3. #3
    Join Date
    Nov 2004
    Posts
    20

    Re: Check this little assingment of arithmatic operation...

    Dear Synthetic Being!

    Thanx a lot for shortening the code. The speed isn't issue here in shortening the code, it is just an assignment. The "move cx, 04c00" command is to end the programm.

    Thanx once again.


    Mood.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center