flat assembler
Message board for the users of flat assembler.

Index > DOS > Can this be optimized any further?

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Can this program that makes a screen full of t.v. static be optimized any further?

Code:
;Static program
;Created April 5,2007 by windwakr
;assembled size is 31 bytes

org 100h      ;make it a .com program

les si,[bx]   ;small way to put 0a000h into es

mov ax,13h    ;video mode
int 10h       ;video mode

main:
in ax,40h     ;random number (i think its counter on clock?)
add di,ax     ;without this the static looks like crap
and al,0fh    ;make color greyscale
add al,10h    ;same as above
stosb         ;write color to screen
loop main     ;loop 65535 times

keycheck:
dec cx        ;easy way to make cx ffffh when it is at 0....
in ax,60h     ;get key
dec al        ;decrease it
jnz main      ;if it is not zero jump to main
mov ax,03h    ;text mode
int 10h       ;text mode
ret           ;clean exit
    


Thank you Very Happy

_________________
----> * <---- My star, won HERE
Post 08 Apr 2007, 18:54
View user's profile Send private message Reply with quote
eek



Joined: 21 Oct 2006
Posts: 24
eek
Very impressive.

I replaced ret with

mov ax,4C
int 21

because it blew my computer up when I tried to exit.

41 bytes

ALT-ENTER cycles it in from Window to fullscreen.

Many bytes are boilerplate once you get to this level, like with HELLOWORLD at 16 to 25 bytes.
Post 09 Apr 2007, 00:15
View user's profile Send private message Reply with quote
eek



Joined: 21 Oct 2006
Posts: 24
eek
The video superiority of DOS compared to WINDOWS is phenomenal.
Post 09 Apr 2007, 00:27
View user's profile Send private message Reply with quote
rain_storm



Joined: 05 Apr 2007
Posts: 67
Location: Ireland
rain_storm
you can shave two more byte off it by removing dec cx altogether since the CPU will decrease it at the loop before checking for zero. and the second byte can be earned by replacing mov ax,03 with mov al,03 since ah is already garaunteed to be zero that will bring it down to 29b
very good optimisations what I found impressive for a 32b was the fact that you not only included an exit but also went that little bit further and exited cleanly in text mode Very Happy

edit -
I just noticed you have mov ax,13h if you replace that with mov al,13h you get 28b
Post 09 Apr 2007, 02:31
View user's profile Send private message Reply with quote
JMGK



Joined: 26 Aug 2005
Posts: 27
JMGK
hi,

you can terminate the program with a INT 20h

altought is 1 byte bigger than the RET, is garanteed to work, and is 2 bytes shorter than MOV AH,4C/INT 21h

jmgk
Post 09 Apr 2007, 14:24
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
hardware i/o is way too slow over 65535 irritations. try this instead

Code:
;Created April 5,2007 by windwakr 
;assembled size is 31 bytes 

org 100h      ;make it a .com program 

; - modified by me - hayden mckay

; les si,[bx]   ;small way to put 0a000h into es

mov ax,13h    ;video mode 
int 10h       ;video mode 

push word 0A000h
push word 00040h
pop  ds
pop  es

mov  si, 006Ch
xor  di, di

main:
; in  ax,40h    ;random number (i think its counter on clock?)

; try each of theese

; lodsw             ; looks way too fast ( need a wait retrace for this one )
lodsb               ; looks ok

; mod ends... hayden mckay

add di,ax     ;without this the static looks like crap
and al,0fh    ;make color greyscale
add al,10h    ;same as above
stosb         ;write color to screen
loop main     ;loop 65535 times

keycheck: 
dec cx        ;easy way to make cx ffffh when it is at 0....
in ax,60h     ;get key
dec al        ;decrease it
jnz main      ;if it is not zero jump to main
mov ax,03h    ;text mode
int 10h       ;text mode
ret           ;clean exit

int 20h
    



off topic

someone pointed out to use mov al, 13h. I think you should stick to mov ax, 13h as it guard against some bios bugs.

also you should always initiate required registers instead of putting trust into command.com to preset registers for you.

_________________
New User.. Hayden McKay.
Post 09 Apr 2007, 17:48
View user's profile Send private message Reply with quote
rain_storm



Joined: 05 Apr 2007
Posts: 67
Location: Ireland
rain_storm
Quote:
les si,[bx] ;small way to put 0a000h into es

Quote:

in ax,60h ;get key
dec al ;decrease it
jnz main ;if it is not zero jump to main

this implies that windwakr is optimisng for size not performance my guese is that this is a 32byte demo in which every byte that can be shaved off is a blessing and hard won. what makes mov al,13h unstable? ax has not been touched prior to setting the video mode so it is still zero
Post 09 Apr 2007, 19:41
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
The code ran realy slow on my Pii400mHz ( about ~1-2 secs between frames). I assumed he was looking for speed.

Usualy ax, bx are init to zero but other registers seem to vary. I hav'nt seen any standards before describing the state of general registers for com files except that all segment registers are init to point to start of psp.

Can anyone point me com reference that describes the gerneral registers?
Post 10 Apr 2007, 03:43
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Hayden, I assume this is what you want:

http://www.frontiernet.net/~fys/yourhelp.htm

EDIT: I can indeed confirm that some demo programs assume registers that aren't correct for e.g. DR-DOS 7.03 (like chut.rar, the 253-byte, Winnie-the-Pooh-drawing .COM ... only works upon tweak / reassemble with DEBUG equ 1).

Code:
# WINNIE.SED (for CHUT.RAR from http://www.256b.com) -- converts to FASM

s/\t/ /g
/^\.model tiny/s/^/;/
/^\.code/s/^/;/
/^\.486/s/^/;/
/^ *END /s/^/;/
s/ENDIF/end if/
s/\(o *EQU\).*/\1/
s/\([a-zA-Z0-9_][a-zA-Z0-9_]*\) *\(MACRO\)/\2 \1/
/MACRO/s/;.*/{/
s/ENDM/}/
/STOP *EQU/!{
/s *EQU/!s/ EQU /=/
}

# for DR-DOS 7.03 only (adds 20 bytes)
/\(DEBUG *=\).*/s//\1 1/
    


Last edited by rugxulo on 05 Jun 2007, 13:39; edited 1 time in total
Post 24 May 2007, 06:33
View user's profile Send private message Visit poster's website Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
AX and BX can be nonzero at startup. If your first command line argument is a filename with an invalid drive letter (like "Z:\blah") then AL and BL are 0FFh. If the second argument is, then AH and BH are.
Post 24 May 2007, 14:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.