• 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

Tidied up, redundant line removed; 53 bytes, sets the screen mode at the start, completes the most significant digit, still stops having rolled over to zero rather than at 999..9, still doing only ten digits (change lines 7 and 9 for more or less):

Code:
mov ax,2
int 10
mov ax,b800
mov ds,ax
mov es,ax
mov ax,0730
xor di,di
mov cx,0a
rep stosw
mov di,12
mov al,[di]
inc al
cmp al,3a
je 125
mov [di],al
jmp 116
mov al,30
mov [di],al
sub di,2
js 130
jmp 119
mov ax,4c00
int 21
 
Tidied up, redundant line removed; 53 bytes, sets the screen mode at the start, completes the most significant digit, still stops having rolled over to zero rather than at 999..9, still doing only ten digits (change lines 7 and 9 for more or less):

Code:
mov ax,2
int 10
mov ax,b800
mov ds,ax
mov es,ax
mov ax,0730
xor di,di
mov cx,0a
rep stosw
mov di,12
mov al,[di]
inc al
cmp al,3a
je 125
mov [di],al
jmp 116
mov al,30
mov [di],al
sub di,2
js 130
jmp 119
mov ax,4c00
int 21

Well done. If you remember the original constraints you'll shave 5 bytes off the code. Use debug to set the mode for you.

Nick, respect.

Alexei, you blow goats!
 
---------------------------
MOV AX, 4C00h
INT 21h ; DOS Function Call
---------------------------

RET

will work so long as stack is not buggered, this should be like what 6 bytes reduction? :smokin
 
---------------------------
MOV AX, 4C00h
INT 21h ; DOS Function Call
---------------------------

RET

will work so long as stack is not buggered, this should be like what 6 bytes reduction? :smokin

Alexei you've done f**k al apart from bitch about the tools, insult me and crib from Nick. You still blow goats.

If you had any ability you'd have risen to the challenge last night instead of gobbing off like a twat.

Do you seriously think that I don't have an optimised version of that code?

Nick, well done!

AtW you've shown yourself up!
 
---------------------------
MOV AX, 4C00h
INT 21h ; DOS Function Call
---------------------------

RET

will work so long as stack is not buggered, this should be like what 6 bytes reduction? :smokin

Well, the DOS call takes care of some houskeeping that might be required by certain execution contexts, such as DOS shells that mimic task switching and so forth (like Win3.1):

- restores the terminate, ~Ctrl-Break~, and critical error exit addresses, flushes all buffers, frees memory and returns to DOS via the termination handler address.

- http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte835c.htm
​

Also, AL contains the return code, which would be useful if this was being run from a batch file which wanted to take some special action in the event of abnormal termination.
 
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
 
Well, the DOS call takes care of some houskeeping that might be required by certain execution contexts, such as DOS shells that mimic task switching and so forth (like Win3.1):

- restores the terminate, ~Ctrl-Break~, and critical error exit addresses, flushes all buffers, frees memory and returns to DOS via the termination handler address.

- http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte835c.htm
​

Also, AL contains the return code, which would be useful if this was being run from a batch file which wanted to take some special action in the event of abnormal termination.

It's valid optimisation - the program did what was required and terminated, return error codes are not required in the original spec and looking at what it does also does not require such return code.

Stand by for me posting version of working code that is only 42 bytes long :smokin
 

Advertisers

Back
Top