flat assembler
Message board for the users of flat assembler.

Index > Main > Halfbyte zero check

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
pete



Joined: 20 Apr 2009
Posts: 110
pete 15 May 2009, 08:53
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!
Post 15 May 2009, 08:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 15 May 2009, 09:03
Code:
test al,0xf    
Post 15 May 2009, 09:03
View user's profile Send private message Visit poster's website Reply with quote
pete



Joined: 20 Apr 2009
Posts: 110
pete 15 May 2009, 09:09
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.
Post 15 May 2009, 09:09
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 15 May 2009, 20:53
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?
Post 15 May 2009, 20:53
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 15 May 2009, 21:13
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
Post 15 May 2009, 21:13
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 16 May 2009, 02:15
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. Sad

Four bits are called a nibble. Very Happy
Post 16 May 2009, 02:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 16 May 2009, 09:48
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.
Post 16 May 2009, 09:48
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 16 May 2009, 19:40
Why not and al,15? Confused (or 0xf, or whatever)
Post 16 May 2009, 19:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 16 May 2009, 19:45
Because the topic turned silly at the fourth post, so posting sensible suggestions like and al,15 is not expected. Razz
Post 16 May 2009, 19:45
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 16 May 2009, 19:58
How about this then?

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

Cool
Post 16 May 2009, 19:58
View user's profile Send private message Reply with quote
pete



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

Code:
mov cl,4
    


instead of
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!
Post 18 May 2009, 06:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 18 May 2009, 06:24
pete wrote:
instead of
Code:
mov cl,1
shr cl,2    
Maybe you mean this?
Code:
mov cl,1
shl cl,2    
Post 18 May 2009, 06:24
View user's profile Send private message Visit poster's website Reply with quote
pete



Joined: 20 Apr 2009
Posts: 110
pete 18 May 2009, 06:28
Erm, yes...
Post 18 May 2009, 06:28
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 18 May 2009, 07:58
pete wrote:
instead of
Code:
mov cl,1
shr cl,2
    


Because shr cl,2 doesn't work on 8086 Idea nor shl cl,2 btwww Idea
Post 18 May 2009, 07:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 18 May 2009, 08:14
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. Wink
Post 18 May 2009, 08:14
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 18 May 2009, 17:28
What about using virtual machines for fooling around with a bad algo? Laughing
Post 18 May 2009, 17:28
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 May 2009, 01:32
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?
Post 23 May 2009, 01:32
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 23 May 2009, 09:13
> I thought half a byte is called a nibble? Aren't four bytes called a dword?

Sure, pete is wrong. 4 Bytes = DWORD = ?INT32
Post 23 May 2009, 09:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 23 May 2009, 12:38
Depends upon the CPU, ARM call a 4 byte value a word. Razz
Post 23 May 2009, 12:38
View user's profile Send private message Visit poster's website Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 23 May 2009, 13:47
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.
Post 23 May 2009, 13:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.