• 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

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 :smokin
 
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 :smokin

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
 
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 :smokin

It's called listening to the requirements and constraints, something that you can't be arsed doing.
 
Code:
	dec di		; 2 bytes rather than 3 bytes sub di,2
	dec di

:spel 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.
 
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 :tongue
 
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.
 
Pity you couldn't have done this last night instead of resorting to insults.

I was in a pub with friends last night :tongue

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...
 
42 bytes - where is everyone? :mad

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
 

Advertisers

Back
Top