Measuring assembly instruction byte size (code length)

Bare metal programming in PureBasic, for experienced users
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Measuring assembly instruction byte size (code length)

Post by Trond »

Code: Select all

; Measure the code size in bytes of assembly instructions
!@@:
; Instructions here
!mov [v_size], $-@b
Debug size
Example:

Code: Select all

!@@:
!mov rax, 0
!mov [v_size], $-@b
Debug size

!@@:
!xor rax, rax
!mov [v_size], $-@b
Debug size

!@@:
!push 0
!pop  rax
!mov [v_size], $-@b
Debug size
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Measuring assembly instruction byte size (code length)

Post by Olliv »

Good stuff. Bypasses Disassembly lib which is more complex to code, and less light than this.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Measuring assembly instruction byte size (code length)

Post by Mijikai »

Olliv wrote:Good stuff. Bypasses Disassembly lib which is more complex to code, and less light than this.
Don't u need to know the size already since u need to know where to put this... ?
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Measuring assembly instruction byte size (code length)

Post by Olliv »

https://www.purebasic.com/documentation ... embly.html
Mijikai wrote:Don't u need to know the size already since u need to know where to put this... ?
I have no time to need to know where to put this : I was stolen this before. But I stamped a QRCode on this. No problem anymore.
Post Reply