• 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

    #91
    Originally posted by Churchill View Post
    Nick, don't forget that debug sets the correct display mode as a side effect so you can shave the first 5 bytes and still be safe. That was in the constraints
    That's cheap optimisation. I've used better one that is more reliable - text mode is still set but not the way you'd expect it old dog

    Comment


      #92
      42 bytes long, still works - I even added comments for the awed noobs reading this thread, and in their number I include our own Supreme Spod

      Code:
          code     SEGMENT
                   ASSUME CS:code, DS:code
                   ORG 100h
        
          strt:
      
      	mov ax,0b800h
      
      	int 10h		; al is 0 to set video mode, b8 is invalid video mode, so text mode is used - saves 3 bytes: 	mov ax,2
      
      	mov ds,ax
      	mov es,ax
      	mov ax,0730h
      	xor di,di
      	mov cx,0ah
      	rep stosw
      
      	mov dl,30h	; put constant in register outside main loop
      
      Label_116:
      
      	mov di,12h
      
      Label_119:
      	mov al,[di]
      	inc ax		; 1 byte opcode rather than 2 bytes in: inc al
      	cmp al,3ah
      	
      	je Label_125
      
      	mov [di],al
      
      	jmp Label_116
      
      Label_125:
      
      	mov [di],dl
      
      	dec di		; 2 bytes rather than 3 bytes sub di,2
      	dec di
      	
      	jns Label_119
      
      	ret		; works in COM files so long as stack undisturbed
      
          code     ENDS
                   END  strt

      Comment


        #93
        42 bytes - where is everyone?

        Comment


          #94
          Originally posted by AtW View Post
          That's cheap optimisation. I've used better one that is more reliable - text mode is still set but not the way you'd expect it old dog
          It's called listening to the requirements and constraints, something that you can't be arsed doing.

          Comment


            #95
            Originally posted by AtW View Post
            Code:
             
            	dec di		; 2 bytes rather than 3 bytes sub di,2
            	dec di
            Depending on processor:
            • 8086: 6 cycles instead of 4
            • 80286: 4 cycles instead of 3
            • 80386: 4 cycles instead of 2
            • 80486: 2 cycles instead of 1


            The byte savings are good, but for that one you're better off sacrificing a byte to save the extra cycles, given that this is within a loop that is being executed many billions of times.

            Comment


              #96
              Originally posted by NickFitz View Post
              The byte savings are good, but for that one you're better off sacrificing a byte to save the extra cycles, given that this is within a loop that is being executed many billions of times.
              I moved one register load outside of loop - so I'd say I gained performance and spent it wisely on making file size smaller

              Comment


                #97
                Originally posted by AtW View Post
                42 bytes - where is everyone?
                Pity you couldn't have done this last night instead of resorting to insults.

                Comment


                  #98
                  Originally posted by Churchill View Post
                  It's called listening to the requirements and constraints, something that you can't be arsed doing.
                  I tend to look for the most effective solution that delivers value to our customers - I'll break artificial constraints, rules or people opposing to the right thing if necessary.

                  Frankly this assembly code is a perfect example of when NOT to use assembly.

                  Comment


                    #99
                    Originally posted by Churchill View Post
                    Pity you couldn't have done this last night instead of resorting to insults.
                    I was in a pub with friends last night

                    Now your "insults" thing is a bit of a joke - there were more F-words from you in this thread directed to me than bytes I've saved and I think I did pretty well considering Nick gave your code a good brushing...

                    Comment


                      Originally posted by AtW View Post
                      42 bytes - where is everyone?
                      public class WhereIsEveryOne{
                      public boolean whereIsEveryOne(){

                      String bytesWhereIsEveryone= "programming grew up and so should you" ;

                      }
                      public static void main( String args[] ) {

                      whereIsEveryOne() ;
                      }

                      }

                      END 0.0023 secs

                      Comment

                      Working...
                      X