• 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

Churchill

I live on CUK
Thanks received
133
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: 14:49
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!

:grey
 
AtW, read the original constraints.

BTW, it's an exercise for people to use their brains.
 
Last edited: 15:43
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.
 
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.
 
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. :smokin
 
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!

:fight:
 

Advertisers

Back
Top