Message board for the users of flat assembler.
> Compiler Internals > Any need of "sar", "bsf" or "bsr&qu
Well, "sar" can be equated with
sar equ /1 shl
"bsf" and "bsr" cannot be equated as easy as this, but they are
hardly used or does anyone really need those operators into Fasm?
This is how to implement an "bsf", "bsr" and "sar" operator into Fasm.
;Changes to perform in "EXPRESSI.INC" follow. ;Search for the indicated commands. ;sar - operator: ;--------------- ;After "cmp al,0C1h ; je calculate_shr" cmp al,0C3h je calculate_sar ;After "zero_value:" calculate_sar: mov edx,dword [edi+4] bt edx,31 jc shr_negative mov eax,[ebx+4] or edx,edx jnz sign_value mov ecx,[edi] cmp ecx,64 jae sign_value cmp cl,32 jae sar_high mov edx,[ebx] shrd edx,eax,cl sar eax,cl mov [ebx],edx mov [ebx+4],eax jmp calculation_loop sar_high: cdq sub cl,32 sar eax,cl mov [ebx],eax mov [ebx+4],edx jmp calculation_loop sign_value: cdq mov [ebx],edx mov [ebx+4],edx jmp calculation_loop ;bsf - operator: ;--------------- ;After "cmp al,0D1h ; je calculate_neg" cmp al,0D2h je calculate_bsf cmp al,0D3h je calculate_bsr ;After "calculate_neg:" calculate_bsf: xor edx,edx cmp [edi+8],dx jne invalid_expression cmp [edi+12],dl je bsf_ok cmp [error_line],edx jne bsf_ok mov eax,[current_line] mov [error_line],eax mov [error],invalid_use_of_symbol bsf_ok: bsf eax,[edi] jnz store_result_simple bsf eax,[edi+4] add al,32 store_result_simple: mov [edi],eax mov [edi+4],edx add edi,14h jmp calculation_loop calculate_bsr: xor edx,edx cmp [edi+8],dx jne invalid_expression cmp [edi+12],dl je bsr_ok cmp [error_line],edx jne bsr_ok mov eax,[current_line] mov [error_line],eax mov [error],invalid_use_of_symbol bsr_ok: bsr eax,[edi+4] lea eax,[eax+32] jnz store_result_simple bsr eax,[edi] jmp store_result_simple ;Changes to perform in "PARSER.INC" follow. ;Somewhere at the end of the file. ;Old: operators: db 1,'+',80h db 1,'-',81h db 1,'*',90h db 1,'/',91h db 3,'mod',0A0h db 3,'and',0B0h db 2,'or',0B1h db 3,'xor',0B2h db 3,'shl',0C0h db 3,'shr',0C1h db 0 single_operand_operators: db 1,'+',0 db 1,'-',0D1h db 3,'not',0D0h db 3,'rva',0E0h db 0 ;New: operators: db 1,'+',80h db 1,'-',81h db 1,'*',90h db 1,'/',91h db 3,'mod',0A0h db 3,'and',0B0h db 2,'or',0B1h db 3,'xor',0B2h db 3,'shl',0C0h db 3,'shr',0C1h db 3,'sar',0C3h db 0 single_operand_operators: db 1,'+',0 db 1,'-',0D1h db 3,'not',0D0h db 3,'bsf',0D2h db 3,'bsr',0D3h db 3,'rva',0E0h db 0
MCD - the inevitable return of the Mad Computer Doggy
Last edited by MCD on 05 Jan 2005, 19:10; edited 3 times in total
|29 Nov 2004, 18:58||
I have also thought about implementing "rol" and "ror", but the problem with them is, they are actually tertiary operators (take 3 operands):
The value to rotate, how much to rotate and rotate in which cyclic size (most commonly byte, word or dword wize).
The problem with this, is that Fasm has no tertiary operators in its syntax, and I've no idea how doing this? Privalov?
So, I got to sacrify 1 operand, say the cyclic rotate size. But then, you must specify the rotate size somewhere else, for example like this:
But this would require to implement 8 operators into Fasm and "rolb" does'nt really look good, and you won't be able to rotate, for example, eax by 5 in a cyclic size of 11bits and 11bits can't by done otherwize with the other power of 2 rotatings with reasonable afford.
Anyone an idea?
|29 Nov 2004, 19:08||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.