flat assembler
Message board for the users of flat assembler.
Index
> DOS > How can I make this code look better? |
Author |
|
revolution 13 Jun 2008, 14:52
Not exhaustive but just some ideas ...
|
|||
13 Jun 2008, 14:52 |
|
windwakr 13 Jun 2008, 18:38
This any better?
Code: ;Shows all colors in palette in 2x2 blocks org 100h ;make it .com mov ax,13h ;video mode 320x200 256 colors int 10h ;^^^ push 0a000h ;put screen offset into es pop es ;^^^ xor ax,ax ;zero out ax mov bx,10h ;how many lines vertically will it draw? mov di,6990h ;make it start drawing at a place so the thing will be centered oloop: mov cx,10h ;how many pixels horizantly iloop: stosb ;plot color in 2x2 block stosb ;^^^ add di,13eh ;^^^ stosb ;^^^ stosb ;^^^ sub di,140h ;^^^ inc ax ;increase color loop iloop ;loop 16 times add di,260h ;go to next line down on screen dec bx cmp bx,0h ;have we drawn all 16 lines? jne oloop ;no? continue drawing.....if yes, then keep going key: in ax,60h ;get key press dec ax ; jnz key ;was it esc? if not, go back to key checker mov ax,03h ;return video mode int 10h ;^^^ ret ;exit |
|||
13 Jun 2008, 18:38 |
|
revolution 13 Jun 2008, 19:04
wrote: This any better? Think about using x_size=320, y_size=200, block_height=2, etc. Perhaps the constant 6990h could be converted to the calculation i.e. Code: start_corner = 84*x_size+(x_size-block_width*block_count_x)/2 |
|||
13 Jun 2008, 19:04 |
|
bitRAKE 14 Jun 2008, 01:16
This is just another way to code that same thing:
Code: ;Shows all colors in palette in 2x2 blocks org 100h ;make it .com mov ax,13h ;video mode 320x200 256 colors int 10h ;^^^ push 0a000h ;put screen offset into es pop es ;^^^ ;make it start drawing at a place so the thing will be centered mov di,6990h-120h mov cx,10h ;how many color columns horizontally xor ax,ax ;start with color zero .0: add di,120h ;go to next line down on screen push cx push cx ; first line .1a: stosw add ax,0101h ;increase color loop .1a add di,120h ;go to next line down on screen sub ax,1010h ;back-up to starting line color pop cx ; second line .1b: stosw add ax,0101h ;increase color loop .1b pop cx jnc .0 key: in ax,60h ;get key press dec ax ; jnz key ;was it esc? if not, go back to key checker mov ax,03h ;return video mode int 10h ;^^^ ret ;exit _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
14 Jun 2008, 01:16 |
|
windwakr 14 Jun 2008, 02:35
neat. I was gonna use stosw but wasn't thinking right and it was annoying me.
mine is 1 byte smaller |
|||
14 Jun 2008, 02:35 |
|
bitRAKE 14 Jun 2008, 04:08
windwakr wrote: mine is 1 byte smaller Oh, don't go there - I'll have to break out the can of whoop ass, lol! (down to 45 bytes so far...) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
14 Jun 2008, 04:08 |
|
edfed 14 Jun 2008, 07:03
Code: mov ax,0c00h ; clear keyboard buffer int 21h in AL,60h ; scancode port is a byte, not a word. |
|||
14 Jun 2008, 07:03 |
|
DOS386 14 Jun 2008, 11:33
edfed wrote:
> ; scancode port is a byte, not a word. Exactly ... same bug in both threads ... also see the other one for shot |
|||
14 Jun 2008, 11:33 |
|
windwakr 14 Jun 2008, 12:30
Thanks for showing me all the errors in my code.
|
|||
14 Jun 2008, 12:30 |
|
bitRAKE 15 Jun 2008, 07:32
It is fairly common to assume register values on entry to a COM program - especially when it comes to size optimization. The Hugi competition use the following values:
Code: ; AX BX = 0000 ; CX = 00FF ; DX CS DS ES SS = .... (same unknown value) ; SI = 0100 ; DI = FFFE ; BP = 09.. ; SP = FFFE ; IP = 0100 Code: org $100 mov al,$13 int $10 les dx,[bx] xchg ax,bx ; salc mov di,$6880 .0: add di,$0120 mov cl,$10 .1: stosb stosb inc ax loop .1 add ax,$00F0 lahf jc .0 add al,$10 jne .0 key: in ax,60h dec ax ;more compatible? code, another byte ; in al,$60 ; dec al jnz key mov al,03h int 10h ret I'd like to just reformulate the problem to fit easier code. Maybe, just produce a centered 16x16 grid of similar rectangles displaying all the colors? Adds quite a bit of freedom, imho. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
15 Jun 2008, 07:32 |
|
revolution 15 Jun 2008, 07:50
bitRAKE: The OP isn't looking to make the code small (and harder to understand), the OP wanted to make the code readable.
|
|||
15 Jun 2008, 07:50 |
|
bitRAKE 16 Jun 2008, 02:12
Thought he already reached that goal?
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
16 Jun 2008, 02:12 |
|
AlexP 16 Jun 2008, 02:23
About the indenting, I usually do this:
- Align all instructions to 16 spaces from left - Align beginning of operands 8 spaces after (3-letters + 5 spaces) - Keep a space after commas between operands About labels, I do: - Keep major code labels along left hand of editor - Preceed common, minor labels with '@@', six spaces from left - Keep a line before labels - Keep labels on seperate lines (no 'Label: instruction' ) - Keep a label operand two spaces before usual location (see below) Amounts to: Code: ; Set up an SEH for reading exceptions later lea eax, [ebp+offset Exception] push eax ; SEH handler will just push dword [fs:0] ; exit on exception mov [fs:0], esp ; Now find Kernel32 using return address on stack mov eax, [esp+2Ch] and eax, 0FFFFF000h mov ecx, 100h ; ecx is a counter for loop @@FindKernelHeader: sub eax, 1000h ; loop backwards until you find cmp word [eax], 'MZ' ; what looks like a header jz @@CheckKernelForPESignature ; check for PE loop @@FindKernelHeader ; try again jmp ExitTANGAR ; couldn't find it... @@CheckKernelForPESignature: mov ebx, [eax+3Ch] ; PE signature RVA add ebx, eax ; PE signature address cmp word [ebx], 'PE' ; check if it's PE format jnz @@FindKernelHeader ; And then search it's export table to find GetProcAddress @@KernelFound: mov ebx, [ebx+78h] ; export table RVA add ebx, eax ; export table address ... And you get it... I believe it's a nice structure to it. |
|||
16 Jun 2008, 02:23 |
|
DOS386 16 Jun 2008, 10:07
bitRAKE wrote: It is fairly common to assume register values on entry to a COM program - especially when it comes to size optimization. Common ... maybe ... good idea : NO Code: key: in ax,60h dec ax ;more compatible? code, another byte ; in al,$60 ; dec al AX doesn't work at all here ... you could just use Code: cli hlt or Code: int3 for same effect > how can I make this look better? - Place a (C) or (CL), date, author, hint about complier used (FASM), what it is supposed to do, ... - Use comments (here Tomasz is not the best example ) - Align instructions and operands - Write 0 as "0" , not "0h" - FASM also allows to prefix hex with a $ Just see some of my examples: http://board.flatassembler.net/topic.php?t=8670 _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
16 Jun 2008, 10:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.