flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2 |
Author |
|
revolution 27 Apr 2010, 06:12
Code: xor edx,edx mov dl,[col] Code: movzx edx,[col] |
|||
![]() |
|
revolution 27 Apr 2010, 11:09
Well col should be defined as byte-sized in the source. Catches a lot of programming errors when the sizes are specified beforehand. If you use overrides everywhere then what happens if you later decide to make 'col' a word-sized value?
|
|||
![]() |
|
Fanael 27 Apr 2010, 11:22
Ah, I was wrong - if col is defined as a byte or a halfword then your code compiles just fine. FASM never ceases to astonish me.
|
|||
![]() |
|
edfed 27 Apr 2010, 11:32
X*80 = X*64+X*16 = (X*4+X)*16
then, for fastnes... Code: push eax edx movzx eax,byte[row] movzx edx,byte[col] lea eax,[eax*5] shl eax,4 add eax,edx mov [pos],eax pop edx eax ret and for more speed, use parameter passing through registers. it will save the clocks used to save registers then: Code: movzx eax,[row] movzx edx,[col] call setpos mov [pos],eax ... setpos: lea eax,[eax*5] shl eax,4 add eax,edx ret Last edited by edfed on 27 Apr 2010, 11:40; edited 2 times in total |
|||
![]() |
|
revolution 27 Apr 2010, 11:39
edfed: Sure, as long as the multiplier 80 never changes, ever, then no problem.
![]() |
|||
![]() |
|
edfed 27 Apr 2010, 11:41
if multiplier change, then use imul via a memory operand
Code: mul eax,[Xres] |
|||
![]() |
|
Fanael 27 Apr 2010, 11:53
No ARM version yet?
Code: ldrb r0, [row] ldrb r1, [col] add r0, r0, r0, lsl #2 add r0, r1, r0, lsl #4 strh r0, [pos] bx lr row db ? col db ? pos dh ? ![]() |
|||
![]() |
|
revolution 27 Apr 2010, 11:56
Fanael wrote: No ARM version yet? Quote: flat assembler for ARM version 1.69.13 (216715 kilobytes memory) Code: 00000000: E5DF0010 V1 ldrb r0,[r15,0x10] ;=[0x18] 00000004: E5DF100D V1 ldrb r1,[r15,0xD] ;=[0x19] 00000008: E0800100 V1 add r0,r0,r0,lsl 2 0000000C: E0810200 V1 add r0,r1,r0,lsl 4 00000010: E1CF00B2 V4 strh r0,[r15,0x2] ;=[0x1A] 00000014: E12FFF1E V4T bx r14 |
|||
![]() |
|
LocoDelAssembly 27 Apr 2010, 13:22
Code: update_pos: pushad mov eax, 80 mul [row] ; EAX[0:15] = 80*[row]; EAX[16:31] = 0 movzx edx, [col] add eax, edx ; row*80+col mov [pos], eax ; pos=row*80+col popad ret update_pos_dword: pushad imul eax, [row_dd], 80 add eax, [col_dd] ; row*80+col mov [pos], eax ; pos=row*80+col popad ret |
|||
![]() |
|
edfed 27 Apr 2010, 15:51
why pushad, there are only EAX and EDX to save in the first case, and olnly EAX in the second.
pushad is only one instruction, but it use a lot of cycles for nothing in theses cases. |
|||
![]() |
|
Fanael 27 Apr 2010, 16:05
There's no need to preserve anything at all, EAX and EDX can be clobbered according to most calling conventions (if you're not using one of these, then ignore this post).
|
|||
![]() |
|
LocoDelAssembly 27 Apr 2010, 17:08
Quote:
Yep, I just copy&pasted the code without paying any attention to the prologue and epilogue, the second should be "push eax"/"pop eax". I wanted to optimize for size*, since I guessed this function is probably not used much and it is best to save the code cache for more important stuff, "push eax edx" takes more space than pushad. *Some tricks could be applied to further reduce size if the three variables are known to be near from each other. Perhaps BCD tricks can do something here too? |
|||
![]() |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.