Jump to content
xisto Community
Sign in to follow this  
DrK3055A

What Do This Code In Assembler. A small piece of code can do magic.

Recommended Posts

The following source code was a self-challenge to see if i could program such algorythm in assembler and generate the smallest file possible that keeps the functionality of my program. This is sort of minimalistic programming.

Here is the code. It generates a 432byte length .COM executable file that needs to run from command line at full screen (uses graphic resources). So, what is this program for?, do you dare to give an answer?

;To assemble, use A86 assembler under DOS/WIN machine. It generates a 432 byte COM executable.		SCRX	equ LOOP1-2		SCRY	equ LOOP2-2		INCX	equ INITCOORD+400		INCY	equ INCX+10		ITER	equ INCY+10		MOUSX   equ ITER+2		MOUSY   equ ITER+4		XMIN	equ INITCOORD+15		XMAX	equ INITCOORD+25		YMIN	equ INITCOORD+35		YMAX	equ INITCOORD+45		CUATRO  equ INITCOORD+55INITMB: MOV CX,200		MOV W[ITER],CX		LEA DI,INITCOORD+15  		REP STOSB		LEA SI,INITCOORD		LEA DI,INITCOORD+15+7		MOV CL,50-7		XOR AH,AHL0:	 CMP AH,10		JNE L3		XOR AH,AHL3:	 XOR AL,AL		CMP AH,2		JA  L1		LODSBL1:	 STOSB		INC AH		LOOP L0		THEMB:		MOV AX,02					INT 33hDELTAVALUE:				  		   FINIT			 		   FLD T[XMAX]	   		   FLD T[XMIN] 		   FSUBP ST(1),ST			   FILD W[SCRX]	  		   FDIVP ST(1),ST			   FSTP T[INCX] 		   FLD T[YMAX]	   		   FLD T[YMIN]	   		   FSUBP ST(1),ST 		   FILD W[SCRY] 		   FDIVP ST(1),ST 		   FSTP T[INCY]		MOV AX,12h 		INT 10h			  DRAWMB:		   FINIT			 		   FLD T[XMIN]	   		   FLDZ			  		   MOV CX,640		LOOP1: 			  PUSH CX					  FLD T[YMIN]				  FSTP ST(1)	 			  MOV CX,480	 LOOP2: 				 PUSH CX		 				 CALL ITERING					 FLD T[INCY]	 				 FADDP ST(1),ST  				 POP CX		  				 LOOP LOOP2	  			  FLD T[INCX]					  FADDP ST(2),ST	 			  POP CX			 			  LOOP LOOP1		MOUSEHANDLE: 			  XOR AX,AX		 			  INT 33h 			  OR AL,AL		  			  JE EXIT3		  			  INC AX						  INC AX			  INT 33h		   MWAIT: 			  MOV AX,100h	   			  INT 16h 			  JNZ EXIT3		 			  MOV AX,3		  			  INT 33h									  CMP BL,1		  			  JE  ZOOM		  			  JL  MWAIT		 			  JMP INITMB				XOR AX,AX			   		INT 16h EXIT3:  MOV AX,2		INT 33h		MOV AX,3 		INT 10h				 		MOV AH,09 		LEA DX,[SIGNATURE] 		INT 21h				 		MOV AX,4C00h					INT 21hZOOM: 		SUB DX,120			  		SUB CX,160			  		CALL ZOOM_TMP		ADD DX,240			  		ADD CX,320			  		CALL ZOOM_TMP		FSTP T[YMAX]					FSTP T[XMAX]					FSTP T[YMIN]					FSTP T[XMIN]		ADD W[ITER],150		 		JMP THEMB			   ITERING: 		FLDZ				  		FLDZ				  		FLDZ 		FLDZ 		MOV DL,0Eh					MOV CX,W[ITER]	 LAZO1: 		FST ST(1)		  		FMUL ST,ST		 		INC DL			 		AND DL,0Fh		 		FXCH ST(1),ST	  		FMUL ST,ST(2)	  		OR DL,DL		   		JNZ SIGUE		  		INC DL SIGUE:  FADD ST,ST		 		FADD ST,ST(4)	  		FINCSTP					FINCSTP					FST ST(1)		  		FMUL ST,ST				   		FXCH ST(1),ST 		FDECSTP 		FST ST(1)		  		FINCSTP 		FCHS			   		FADD ST,ST(1)	  		FADD ST,ST(3)	  		FDECSTP					FDECSTP					FLDZ			   		FADD ST,ST(2)	  		FADD ST,ST(4) 		FLD T[CUATRO]	  		FCOMPP			 		FSTSW AX 		FWAIT 		SAHF 		JNA SALIR		  		LOOP LAZO1		 		XOR DL,DL		  SALIR: 		FSTP ST					FSTP ST					FSTP ST 		FSTP ST 		MOV BP,SP		  		MOV AL,DL		  		MOV CX,640		 		MOV DX,480		 		MOV BX,[BP+2] 		SUB DX,BX 		MOV BX,[BP+4] 		SUB CX,BX 		MOV AH,0Ch					XOR BX,BX			 		INT 10h			   		RET ZOOM_TMP:		MOV W[MOUSY],DX	   		MOV W[MOUSX],CX 		FLD T[INCX]		   		FIMUL W[MOUSX]				FLD T[XMIN]		   		FADDP ST(1),ST				FLD T[INCY]		   		FIMUL W[MOUSY] 		FLD T[YMIN] 		FADDP ST(1),ST 		RETSIGNATURE: 		DB "By DrK3055A.",10,13,'$'INITCOORD:		DB 80h,0,0C0h,0C0h,0FFh,03Fh,0A0h,0FFh,0BFh,0A0h,0FFh,03Fh,080h,1,040h

Also, it was my first atempt for programming the Floating Point Unit by te use of assembler.

Share this post


Link to post
Share on other sites

I am not very sure about it. I am very lazy this saturday morning, and I did not want to messup my head with ASM codes. But, I did look through the labels and variables names you had given through out the code.And then I noticed there are calls to the 33h interrupt handler - from the recesses of my mind, I remember that to be mouse handler. Your labeling too states so. Moreover you have stated that it uses graphics resource. I presume it is a Paint kind of program at the very basic level - na... I do not think 500 odd byte COM can hold that.Or Fractal navigation?

Share this post


Link to post
Share on other sites

Or Fractal navigation?


Yess, you've got the right clue. This is a simple Mandelbrot explorer, it uses int 10h video 640x480x16 graphic mode for drawing, it uses int 33h for mouse handling, and uses int 16h for getchar/kbhit functions.

It uses extended doubles for floating point arithmetic (80 bit prec), and have the capability for zooming x2 when clicking over an area of the mandelbrot set.

I know there are smaller mandelbrot viewers, but not many that can let you zoom until processor capabilities while this is around 400bytes.
Edited by DrK3055A (see edit history)

Share this post


Link to post
Share on other sites

Hurray! I got it.Well, that really is a worthy feat you achieved there. I have still not actually got myself to really understand and vizualize the in-between dimensions that fractals deal with. And with respect to ASM, it was a long time back I was twiddling around with it, when I also did some 8086 coding on trainer boards, and hand built embedded systems on 8051. :Nostalgic:You should though read The Black Book by Michael Abrash - it has got great techniques for optimizations in ASM - both process time wise, as well as foot print wise.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.