fasm 32位转28位算法:remove each byte(Bit 7)

本文介绍了一个优化的函数,用于解码32位值,忽略最高位的每一字节,并返回一个28位的值。通过使用位操作和查找表(LUT),实现高效解码过程。
 
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;*--==--* You are given a 32 bit value where the Most Significant
;*--==--* Bit in each byte (Bit 7) must be ignored, thus encoding
;*--==--* a 28 bit value. Write an optimal function to decode the
;*--==--* value (strip the ignored bits).

;*--==--* By G-Spider
;*--==--* fasm mtTest.asm mtTest.exe
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

format PE console
entry start

include 'win32a.inc'

;---------------------------------------------
section '.text' code readable executable
  start:

    stdcall _UInt32ToUInt28,0f7abh
    cinvoke printf,szFmt,eax

    cinvoke system,szPause
    ret
          
align 16
_UInt32ToUInt28:
        mov eax,dword [esp+4]
        and eax,7f7f7f7fh
        movzx ecx,ax
        shr eax,16
        movzx ecx, word [LUT + ecx * 2]
        movzx eax, word [LUT + eax * 2]
        shl eax,14
        or eax,ecx
        ret 4

;---------------------------------------------
section '.data' data readable writeable
LUT:
repeat 32768
  dw (((%-1) and 0x7F00) shr 1) or ((%-1) and 0x7F)
end repeat

szFmt   db '%x ', 0aH, 00H
szPause db 'pause',0
;---------------------------------------------
section '.idata' import data readable writeable
  library  msvcrt,'msvcrt.dll'
  
  import msvcrt,\
     printf,'printf',\
     system,'system'


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值