flat assembler
Message board for the users of flat assembler.
Index
> Main > Conditional moving without branching Goto page 1, 2 Next |
Author |
|
edfed 03 Apr 2008, 01:34
can you repeat the question please, do not understand...
you can try with a lookup table followed by an addition to obtain numbers more than 255. or cmovcc where cc is the condition code. but is ok for P II +. |
|||
03 Apr 2008, 01:34 |
|
bitRAKE 03 Apr 2008, 02:02
does this work?
Code: cmp eax,192 sbb ebx,ebx cmp eax,256 sbb ecx,ecx and ebx,32 and ecx,12 add eax,ebx lea eax,[eax+ecx-12] _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
03 Apr 2008, 02:02 |
|
AlexP 03 Apr 2008, 02:15
Sorry BitRAKE, your code:
Code: xor ebx, ebx xor ecx, ecx mov eax, 128 cmp eax,192 sbb ebx,ebx cmp eax,256 sbb ecx,ecx and ebx,32 and ecx,12 add eax,ebx lea eax,[eax+ecx-12] produces 244 for the input of 256, not what I needed... It did work for the other two though. I was wondering if this code, the one I regret to use due to branch prediction, would be okay: Code: mov eax, 224 ; default mov ebx, 160 ; other two mov ecx, 190 cmp edi, 192 cmove eax, ecx cmovb eax, ebx If anyone else wants a go, please do! Last edited by AlexP on 03 Apr 2008, 02:35; edited 1 time in total |
|||
03 Apr 2008, 02:15 |
|
edfed 03 Apr 2008, 02:34
are you sure you will have only 3 values?
as i see it is a brief list of normalised samples rates. http://en.wikipedia.org/wiki/Bitrate bitrate, not bitrake. in case of many values, a translation table is the best choice. |
|||
03 Apr 2008, 02:34 |
|
AlexP 03 Apr 2008, 02:37
edfed: Yes, I'm sure I only have three values. You must be mistaking the snippet for something different.
|
|||
03 Apr 2008, 02:37 |
|
revolution 03 Apr 2008, 02:46
I know what these values are for, SHA code. Nothing else would use values like that. But why not a look-up table:
Code: table: dd 160,192,224 ... mov eax,[input_value] shr eax,6 ;edited from 7, thanks edfed mov eax,[table+eax*4-8] Last edited by revolution on 03 Apr 2008, 03:05; edited 1 time in total |
|||
03 Apr 2008, 02:46 |
|
edfed 03 Apr 2008, 02:59
your code is ambiguous. 192 shr 7 = 128 shr 7.
Code: table dd 160,192,224 ... mov eax,[value] shr eax,6 mov eax,[table+eax*4-8] i was thinking it was the common values of MP3 bit rates. |
|||
03 Apr 2008, 02:59 |
|
revolution 03 Apr 2008, 03:04
Yes, you are correct. I'll edit above just to avoid confusion.
|
|||
03 Apr 2008, 03:04 |
|
sinsi 03 Apr 2008, 03:29
Code: mov eax,[value] mov ecx,160 mov edx,224 cmp eax,192 ;if eax=192 then it doesn't change cmovb eax,ecx ;if eax=128 then eax=160 cmova eax,edx ;if eax=256 then eax=224 |
|||
03 Apr 2008, 03:29 |
|
edfed 03 Apr 2008, 03:45
Quote: I was wondering if this code, the one I regret to use due to branch prediction, would be okay: |
|||
03 Apr 2008, 03:45 |
|
bitRAKE 03 Apr 2008, 03:59
AlexP wrote: Sorry BitRAKE, your code produces 244 for the input of 256 Code: cmp eax,192 sbb ebx,ebx cmp eax,256 sbb ecx,ecx and ebx,32 and ecx,32 add eax,ebx lea eax,[eax+ecx-32] _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
03 Apr 2008, 03:59 |
|
DOS386 03 Apr 2008, 07:03
> What I have is: 128,192,256.
> What I need is: 160,192,224 respectively. Code: ; Input in AL, AX or EAX sub al,128 shr al,1 add al,160 ; Result in AL, AX or EAX I haven't seen an easier ASM "puzzle" and a more silly "justification" for "cool" new "useful" instructions before _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
03 Apr 2008, 07:03 |
|
edfed 03 Apr 2008, 12:54
al cannot contain 9 bits.
256 ==> 9 bits. (192-128)/2+160!=192 (256-128)/2+160!=224 your easy puzzle resolution is completelly false. you presume of your power. Code: 1000_0000b ==> 1010_0000b 128 to 160 1100_0000b ==> 1100_0000b 192 to 192 1_0000_0000b ==> 1110_0000b 256 to 224 this puzzle should be very easy to solve in PURE digital electronics.TTL or CMOS. |
|||
03 Apr 2008, 12:54 |
|
AlexP 03 Apr 2008, 13:28
Quote: I know what these values are for, SHA code. Nothing else would use values like that. But why not a look-up table: These values are actually to calculate the byte offset of the end of an AES decryption key schedule, I think I will reverse the schedule instead of having this odd code run every decryption time. Very intersesting solutions though, thanks! They did give me an idea of how to speed up another part of code, good luck with storing 256 into al DOS386 . |
|||
03 Apr 2008, 13:28 |
|
Goplat 03 Apr 2008, 14:19
This is probably the fastest way to do it:
Code: shr eax,1 add eax,96 |
|||
03 Apr 2008, 14:19 |
|
revolution 03 Apr 2008, 14:26
Goplat wrote: This is probably the fastest way to do it: |
|||
03 Apr 2008, 14:26 |
|
bitRAKE 03 Apr 2008, 15:56
Most likely the smallest too.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
03 Apr 2008, 15:56 |
|
Remy Vincent 03 Apr 2008, 21:02
Code: org 100h use16 mov ax,128 mov bx,192 mov cx,256 mov dx,111 push dx cx bx ax push dx cx bx ax push ds pop es ;--------------- Display all values --------------- mov di,C_Buf25 mov al," " stosb mov al," " stosb mov al," " stosb pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov al,0Dh stosb mov al,0Ah stosb mov [di],byte "$" ; At the end of the string, set $ mov dx,C_Buf25 mov ah,09h ; INT 21h , Function 09h , Display String...$ int 21h ;--------------- Check values --------------- pop ax bx cx dx cmp ax,128 jne IsOk_AX mov ax,160 IsOk_AX: cmp bx,192 jne IsOk_BX mov bx,192 ; The same !!! IsOk_BX: cmp cx,256 jne IsOk_CX mov cx,224 IsOk_CX: cmp dx,111 jne IsOk_DX ;--mov dx,dx-- ; We don't know if value 4 is to be checked IsOk_DX: push dx cx bx ax ;--------------- Display all values --------------- mov di,C_Buf25 mov al,"=" stosb mov al,"=" stosb mov al,">" stosb pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov al,"." stosb ; At the end of the string, set . pop ax call IntegerToEStrZ mov [di],BYTE "$" ; At the end of the string, set $ mov dx,C_Buf25 mov AH,09h ; INT 21h , Function 09h , Display String...$ int 21h ;--------------- / --------------- int 20h ;=============== Data C_Buf25 DB "TEMP BUFFER, SIZE......25" ;=============== Small toolbox ;===== IntegerToEStrZ IntegerToEStrZ: ;AX(I_Number) , ES:DI(I_BufPtr) ==> ES:DI(O_EndingZ) cld ;----- Check sign or ax,ax jns IntegerToEStrZ_ISPOSITIVE IntegerToEStrZ_ISNEGATIVE: mov cl,2Dh ; Store sign mov [di],CL inc di neg ax ; Keep Abs(I_Number) sbb ax,0FFFFh IntegerToEStrZ_ISPOSITIVE: mov bl,0 ; BL (L_StrModifiedQ) mov cx,10000 ; CX (L_Divisor) ;----- LOOP , Char 1..4 ( NNNNx ) IntegerToEStrZ_LOOP: xor dx,dx div cx ; DX:AX div CX ==> DX(rest) AX(result) ;----- Ignore left 0 or al,al jnz IntegerToEStrZ_STORE or bl,bl jz IntegerToEStrZ_NEXT IntegerToEStrZ_STORE: add al,30h stosb mov bl,1 ; Modified IntegerToEStrZ_NEXT: mov ax,dx ;----- 10000 ==> 1000 ( ==> 100 ==> 10 ) cmp cx,10 je IntegerToEStrZ_LAST xor dx,dx xchg ax,cx mov si,10 div si xchg ax,cx jmp IntegerToEStrZ_LOOP IntegerToEStrZ_LAST: ;----- Store last char ( xxxxN ) add al,30h stosb ;----- Store ending char 0 mov al,0 mov [di],al ret
|
|||||||||||
03 Apr 2008, 21:02 |
|
Goplat 03 Apr 2008, 22:19
bitRAKE wrote: Most likely the smallest too. |
|||
03 Apr 2008, 22:19 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.