flat assembler
Message board for the users of flat assembler.

 Index > Main > Halfbyte zero check Goto page 1, 2  Next
Author
pete

Joined: 20 Apr 2009
Posts: 110
pete
I wonder if there is a possibility of checking if the lower halfbyte (f.i. of al) is zero without modifying the higher halfbyte. At the moment i'm doing it very complicated this way:

Code:
```    push    eax
shl     al,4
shr     al,4
cmp     al,0
pop     eax
jz      @f
```

Thank you in advance for any suggestions!
15 May 2009, 08:53
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Code:
`test al,0xf    `
15 May 2009, 09:03
pete

Joined: 20 Apr 2009
Posts: 110
pete
Oh gosh [am i dumb]. Thank you revolution!
By the way: this was just to test your skills, of course i already knew the answer.
15 May 2009, 09:09
r22

Joined: 27 Dec 2004
Posts: 805
r22
pete, if you haven't already
spend some time with the Intel/AMD Instruction Set manuals and then the Optimization manuals they are very enlightening.

This thread really highlights the fact that it takes a lot more effort to become competent in ASM then it does in an HLL.

Code:
```//pete's original snippet in a HLL (without resorting to GOTO ln)
//ironically/humorously it's less lines in ASM
unsigned char savedByte = originalByte;
originalByte <<= 4;
originalByte >>= 4;
if( originalByte == 0 ){
originalByte = savedByte;
...
}else{
original = savedByte;
...
}

//rev's micro-snippet in a HLL
if( originalByte & 0xf == 0 ){ ... }

//what a novice/beginner might use in a HLL
if( originalByte << 4 == 0 ){ ... }
//or if ignorant of binary (&) and shift (<<) probably modulus
if( originalByte % 16 == 0 ){ ... }
```

Without full knowledge of an HLL you could muddle along and your ignorance would hardly be noticable to someone experienced in the language, BUT in ASM even the slightest lapse of knowledge can be glaringly obvious.

Facinating realization, don't you think?
15 May 2009, 20:53
windwakr

Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Ya, r22 is right. The manuals are very helpful. In case you don't know where to find them, heres the link.
I always have the instruction set manuals handy, to look through, to find what an instruction does, etc.

I think you should start out by just going through the instruction set part of the "fasm.pdf" file, and then use the intel manuals once you are familiar with most of the instructions.

_________________
----> * <---- My star, won HERE
15 May 2009, 21:13
bitRAKE

Joined: 21 Jul 2003
Posts: 3055
Location: vpcmipstrm
bitRAKE
Code:
`aam 16    `
...works if the contents can be modified. Better than DIV because it sets the flags based on AL's contents, but invalid in long mode.

Four bits are called a nibble.
16 May 2009, 02:15
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
bitRAKE wrote:
Code:
`aam 16    `
...works if the contents can be modified. ... invalid in long mode.
Code:
`shl al,4    `
... works if the contents can be modified and IS valid in long mode.
16 May 2009, 09:48
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Why not and al,15? (or 0xf, or whatever)
16 May 2009, 19:40
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Because the topic turned silly at the fourth post, so posting sensible suggestions like and al,15 is not expected.
16 May 2009, 19:45
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc

Code:
```mov bl, 0
mov cl, 4
@@:
shr al, 1
loop @B    ```
check bl

16 May 2009, 19:58
pete

Joined: 20 Apr 2009
Posts: 110
pete
Aha, four bytes are called a nibble.
Your code is welcome, Borsuc ;) But why is it

Code:
```mov cl,4
```

Code:
```mov cl,1
shr cl,2
```

???

Thanks for the link, windwakr! I already knew this site, stumbled across it some time but haven't used it yet; this will change!
18 May 2009, 06:18
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
pete wrote:
Code:
```mov cl,1
shr cl,2    ```
Maybe you mean this?
Code:
```mov cl,1
shl cl,2    ```
18 May 2009, 06:24
pete

Joined: 20 Apr 2009
Posts: 110
pete
Erm, yes...
18 May 2009, 06:28
DOS386

Joined: 08 Dec 2006
Posts: 1901
DOS386
pete wrote:
Code:
```mov cl,1
shr cl,2
```

Because shr cl,2 doesn't work on 8086 nor shl cl,2 btwww
18 May 2009, 07:58
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Well luckily no one has an 8086 (or an 8088) anymore. And anyone that does have one will find it doesn't work. And anyone that finds it does work will not any good use for it. And anyone that does have a good use for it is not living in the real world.
18 May 2009, 08:14
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
What about using virtual machines for fooling around with a bad algo?
18 May 2009, 17:28
Azu

Joined: 16 Dec 2008
Posts: 1159
Azu
pete wrote:
Aha, four bytes are called a nibble.
I thought half a byte is called a nibble? Aren't four bytes called a dword?
23 May 2009, 01:32
DOS386

Joined: 08 Dec 2006
Posts: 1901
DOS386
> I thought half a byte is called a nibble? Aren't four bytes called a dword?

Sure, pete is wrong. 4 Bytes = DWORD = ?INT32
23 May 2009, 09:13
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Depends upon the CPU, ARM call a 4 byte value a word.
23 May 2009, 12:38
pal

Joined: 26 Aug 2008
Posts: 227
pal
A nibble (some people spell it nybble I think) is 4 bits. It is not half of a byte as a byte is not necissarily 8 bits. I.e. nibble = half of an octet.

There are other ones too.

http://en.wikipedia.org/wiki/Byte wrote:

Similarly to the terms bit, byte, and nibble, other terms of bit groups of varying sizes have been used over time. All of these are jargon, are obsolete, or are not very common.

* 1 bit: sniff
* 2 bits: lick, crumb, quad, quarter, tayste, tydbit
* 4 bits: nibble, nybble
* 5 bits: nickel, nyckle
* 10 bits: deckle, dyme bag
* 16 bits: plate, playte, chomp, chawmp (on a 32-bit machine)
* 18 bits: chomp, chawmp (on a 36-bit machine)
* 32 bits: dinner, dynner, gawble (on a 32-bit machine)
* 48 bits: gobble, gawble (under circumstances that remain obscure)

But it is not half a byte necissarily.
23 May 2009, 13:47
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area
Goto page 1, 2  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum