CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004

    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.

    if (al>bl) AND (bl>cl){
    and I've write the 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.


  2. #2
    Join Date
    Feb 2004
    Helsinki, Finland

    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:
    	cmp	bl,al
    	jae	done
    	cmp	cl,bl
    	jae	done
    	mov	cx,1
    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

    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.


Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.