flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
comrade 25 Nov 2004, 20:12
i don't understand how that works?
|
|||
![]() |
|
revolution 26 Nov 2004, 06:46
so:
x = var sar 4 assembles to: x = var /1 shl 4 which means: x = var/16 Nice ![]() |
|||
![]() |
|
comrade 26 Nov 2004, 16:37
ah good
that keeps sign bit? |
|||
![]() |
|
MCD 29 Nov 2004, 17:02
yes, that keeps sign bit, but is a bit slow.
But if anyone needs a really fast "sar" operator, then you should try implementing "sar" directly into Fasm. I had done this some time ago, but removed it because I didn't use it much! I also implemented "bsf" and "bsr" this way. "bsf" and "bsr" are unary operators, while "sar" is a binary one. If anyone needs such things, feel free to use it, but I don't thing Privalov should implement it in official releases (not used much enough) Code: ;This file describes 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 |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.