• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Code Puzzle

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Code Puzzle

    Below is a piece of code. If you feel like optimising it then please do. It is purely an exercise and for the hard of thinking (AtW), not a competition. Your resulting code must be assembled via debug and if you use a hex listing (in the case of .386 code for example) then please show your source code and explain any optimisations.

    Code:
    A 100
    mov ax,b800
    mov ds,ax
    mov ax,30
    xor di,di
    mov cx,10
    ds:
    mov [di],al
    inc di
    inc di
    dec cx
    cmp cx,0
    jne 10e
    mov di,20
    mov cx,10
    mov al,[di]
    inc al
    cmp al,3a
    je 12A
    mov [di],al
    jmp 118
    mov al,30
    mov [di],al
    dec di
    dec di
    cmp di,0
    je 137
    jmp 11E
    mov ax,4c00
    int 21
    
    N test.COM
    RCX
    3C
    W
    Q
    Have fun.
    Last edited by Churchill; 7 April 2010, 08:08. Reason: Thought I'd put it back the way it was(ish).

    #2
    I'll give you just one hint (free of charge):

    ---------
    inc di
    inc di
    dec cx
    ---------

    is better be:

    ---------
    inc di
    dec cx
    inc di
    ---------

    And another one:

    je 137
    jmp 11E
    ^^^^^^^

    Making absolute jumps to predefined addresses and asking people to change source code that would inevitably change offsets is rather mean.

    And FFS stop programming in 16-bit DOS mode - time to move on!

    Comment


      #3
      AtW, read the original constraints.

      BTW, it's an exercise for people to use their brains.
      Last edited by Churchill; 7 April 2010, 08:08.

      Comment


        #4
        Originally posted by Churchill View Post
        BTW, it's an exercise for people to use their brains.
        Recalculating manually absolute addresses is not exercise for brains - maybe only to weed out those who would actually cave in to this task and accept it as norm, a bit like this: http://www.youtube.com/watch?v=i7ebfrcv4tc

        Your code is sure very poor performance wise, maybe intentionally but in any case when you ask people to optimise assembly you need to say which CPU you are targeting.

        Comment


          #5
          btw, no debug command on Win XP 64 bit

          Comment


            #6
            it'll be a tpyo

            Comment


              #7
              Looks like Churchy made an arse of himself with some poor code from the 1980's.

              Comment


                #8
                Originally posted by DimPrawn View Post
                Looks like Churchy made an arse of himself with some poor code from the 1980's.
                Nope, I thought I'd have a go at posting something that some people may enjoy playing with hence the title of the post.

                AtW decided to be a twat and spoil it.

                Comment


                  #9
                  Originally posted by Churchill View Post
                  Nope, I thought I'd have a go at posting something that some people may enjoy playing with hence the title of the post.
                  I like ASM, however, what's so enjoyable to make people use absolute addresses?

                  AtW decided to be a twat and spoil it.
                  I've saved source code into a file.

                  Comment


                    #10
                    Originally posted by Churchill View Post
                    Nope, I thought I'd have a go at posting something that some people may enjoy playing with hence the title of the post.

                    AtW decided to be a twat and spoil it.
                    For an ex-Royal Marine you are a bit of a coward - run away you big girls blouse!

                    Comment

                    Working...
                    X