• 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

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

Yes, but you can still gain even more performance at the cost of one byte: I'd say it's a no-brainer, given that that code is going to execute, what, 20 trillion times? Probably something like 16!, anyway :eek

Assuming we move on from an 8MHz 8086 to something where it's saving one cycle on a machine running at 5GHz, you'll save over an hour :)
 
Yes, but you can still gain even more performance at the cost of one byte: I'd say it's a no-brainer, given that that code is going to execute, what, 20 trillion times? Something like 16!, anyway :eek

Assuming we move on from an 8MHz 8086 to something where it's saving one cycle on a machine running at 5GHz, you'll save over an hour :)

At that time I was optimising primarily for size, typically it's either speed or size, rarely both.

As I said I took one constant assigned from the loop, so I improved speed of it, then I potentially (depending on CPU) sacrified it by changing to 2 dec's rather than 1 sub.

Since this program is completely retarded in its function the main optimisation target should be size really, it's not like it's doing any useful time sensitive operation.
 
Frankly on old CPUs branch prediction was non existant, so excessive branching in this loop was probably the main performance killer anyway - that and writing directly into memory instead of calculating data in registers and then writing it once into memory.
 
Nick, Churchy seems to have gone a bit quiet now AtW has submitted some code. Can you verify for those of us who can't tell, if it is a valid submission?
 
Code from debug disassembly:

Code:
0100 B800B8        MOV     AX,B800
0103 CD10          INT     10
0105 8ED8          MOV     DS,AX
0107 8EC0          MOV     ES,AX
0109 B83007        MOV     AX,0730
010C 33FF          XOR     DI,DI
010E B90A00        MOV     CX,000A
0111 F3            REPZ
0112 AB            STOSW
0113 B230          MOV     DL,30
0115 BF1200        MOV     DI,0012
0118 8A05          MOV     AL,[DI]
011A 40            INC     AX
011B 3C3A          CMP     AL,3A
011D 7404          JZ      0123
011F 8805          MOV     [DI],AL
0121 EBF2          JMP     0115
0123 8815          MOV     [DI],DL
0125 4F            DEC     DI
0126 4F            DEC     DI
0127 79EF          JNS     0118
0129 C3            RET
 
I was slow with the test please delete thread. I'd like to register an early post here. To be fair I have no idea what this thread is about as I only write commercial code, but as I feel this is going to run and run , I would like to predict that atw wins the argument in 2056 when Churchill eventually gives up when corks it in the old peoples home at the age of 99. Atw will then have a heart attack as he realises that Churchill was right after all and andyws grandson posts the ten millionth reply to the guineas book of records most tedious bulletin board thread in three galaxies!
 
Nick, Churchy seems to have gone a bit quiet now AtW has submitted some code. Can you verify for those of us who can't tell, if it is a valid submission?

Looks OK, but I haven't checked and I'm out at the mo - give me a few minutes to copy it into my notebook (a paper one...) and I'll hand-execute it to check :)
 
Well, AtW's code seems fine, apart from the mode setting (line 2) which looks like a sneaky hack - I'd want some confirmation that it works reliably before putting that into production.

Apart from that, a very nice bit of work :yay:
 

Advertisers

Back
Top