pouët.net

Go to bottom

projected dot-cube in assembler

category: code [glöplog]
 
any ideas for optimization?

Code: org 100h mov al, 13h int 10h mov ax, 0a000h mov es, ax mov bx, -2 mov cx, 8 ;8 vertices L1: add bx, 6 ;translate z mov ax, [cube+bx] add ax, [fovz] mov [cube+bx], ax ;X Coordinate mov ax, [cube+bx-4] ;put x-coord in ax mul word [fovz] ;ax=al*m8 cwd idiv word [cube+bx] ;z-coord ;ax=ax/reg mov [proj], ax ;Y Coordinate mov ax, [cube+bx-2] ;y-coord mul word [fovz] cwd idiv word [cube+bx] ;z-coord mov [proj+2], ax ;plot projected coords push ax push bx ;x-coord mov bx, [proj] ;bx = x add bx, 160 ;bx = x + 160 mov si, bx ;si = x ;y-coord mov ax, 320 mov bx, [proj+2] ;bx = y add bx, 100 ;bx = y+100 mul bx ;ax = (y+100) * 320 add si, ax ;si = x+160 + (y+100) * 320 mov byte [es:si], 15 pop bx pop ax loop L1 a: jmp a fovz dw 255 cube dw -40, -40, -40 dw 40, -40, -40 dw 40, 40, -40 dw -40, 40, -40 dw -40, -40, 40 dw 40, -40, 40 dw 40, 40, 40 dw -40, 40, 40 proj times 2 dw 0


i did the same with just ploting the pixels and came to 41 bytes:
Code: org 100h mov al, 13h int 10h les bp,[bx] mov cx, 8 L: mov si, [cube+bx] mov byte [es:si+255], 15 add bx, 2 loop L cube dw 16833, 16927, 21006, 21074, 42767, 42834, 46913, 47007

but the reason why i am asking is because i want the projection routine to work in real-time. hence doing rotation in pure assembly is the next step for the former routine.
added on the 2011-12-19 11:58:16 by rudi rudi
if you're optimizing for size, you can just go for the equivalent of for(int i=0; i<8; i++) { x = (i&1)?-40:40; y = ... } instead of storing the coordinates
added on the 2011-12-19 12:03:48 by Gargaj Gargaj
yes, good point. thank you
added on the 2011-12-19 12:07:08 by rudi rudi
Quote:
I want the projection routine to work in real-time

is it not working in real-time now? What hardware are you using?
added on the 2011-12-19 12:09:27 by trc_wm trc_wm
trc_wm: hm. dosbox. what? you dont see the dots?
added on the 2011-12-19 12:11:47 by rudi rudi
its not tested on a real dos btw.
added on the 2011-12-19 12:12:27 by rudi rudi
Avoud to use stored values, try to generate all on the fly.
You can save a lot of space
For 8 point it might be like

Code: inc bx mov al, 40 test bl, 1 jz AX sub al, 80 AX: cbw push ax mov al, 40 test bl, 2 jz AY sub al, 80 AY: cbw push ax mov al, 40 test bl, 4 jz AZ sub al, 80 AZ: cbw push ax ;pop them and project coordinates inc bx and bl, 7


or even more aggressive
Code: inc bx test bl, 1 salc xor al, 64 AX: cbw push ax test bl, 2 salc xor al, 64 AY: cbw push ax test bl, 4 salc xor al, 64 AZ: cbw push ax ... inc bx and bl, 7

(gives cube 65x65x65)
added on the 2011-12-19 12:47:27 by frag frag
Oops, change first "inc bx" to "L:"
and add at teh end "jmp L"
added on the 2011-12-19 12:49:28 by frag frag
trc_wm: sorry, i read your line wrong. yes its working in RL.
frag: fantastic! actually i need to understand whats going on in that code. if it is equal to gargaj's C-code then i understand. the salc and test-instructions i havent learned yet, so i don't yet fully understand em.
added on the 2011-12-19 13:10:06 by rudi rudi
i need to wrap up the disassembler in Visual C/C++ and study those instructions. but i need a break now :)
added on the 2011-12-19 13:10:58 by rudi rudi
props for showing actual effort. good luck.
added on the 2011-12-19 18:16:54 by superplek superplek
dunno if this is shorter. it looked scary to implement that one frag.
anyway. this is what i got now

Code: mov al, 128 L: rol al, 1 cmp al, 8 jnz L2 mov al, 1 L2: mov word [cube+bx], 40 test cl, al jnz L3 mov word [cube+bx], -40 L3: add bl, 2 loop L
added on the 2011-12-21 15:19:42 by rudi rudi
just stripped a few byte(s). forgot


Code:L: rol al, 1 cmp al, 8 jnz L2 mov al, 1 L2: mov word [cube+bx], 40 test cl, al jnz L3 neg word [cube+bx] L3: add bl, 2 loop L

added on the 2011-12-21 15:38:23 by rudi rudi
ive changed to NASM. when i do a mul bx, cx for example. is bx the destination operand or does it mul bx and cx (bx*cx) and dest in ax? just wondering
added on the 2011-12-25 23:09:54 by rudi rudi
just did it in ax. didnt bother
added on the 2011-12-26 00:39:21 by rudi rudi
There are three "types" of imul:
  • imul cx,bx,12345: cx = low 16 bits of (bx*12345)
  • imul bx,cx: bx = low 16 bits of (bx*cx)
  • imul bx: ax = low 16 bits of (ax*bx), dx = high 16 bits of (ax*bx)
mul has only the last one (16*16->32).
added on the 2011-12-26 02:52:00 by rrrola rrrola
very helpful, thanks rrrola
added on the 2011-12-26 16:54:23 by rudi rudi

login

Go to top