News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem getting specific bit of variable/register

Started by daniek91, January 15, 2012, 09:13:58 PM

Previous topic - Next topic

daniek91

Hi all ! :)

I'm working on my school project. I'm stuck at getting specific bit value. I need to test bits of AL.
That's what I've done do far :

mov eax,10101010101010101101010101010101b ;just random value for test
mov ecx,8 ;8 because I want to check 8 bits, so I'll loop it 8 times
mov ebx,0 ;number of starting bit

TEST_BITS:
push ecx

bt eax,ebx ;that should return value of ebx bit in eax to CF
jc one
jnc zero

zero:
invoke WriteConsoleA,hout,OFFSET w_zero,1,rout,0 ; writes 0
jmp skip_one

one:
invoke WriteConsoleA,hout,OFFSET w_one,1,rout,0 ; writes 1

skip_one:
inc ebx
pop ecx
loop TEST_BITS


I thought it would work just fine but it always returns "10000000".

I've been looking for an answer for some time now, but I just couldn't find it.
What I've done wrong ? Please help me..



Best regards,
Daniel

Gunner

Works fine.  As we don't know what w_zero or rout is it could be that...

Look in \masm32\vkdebug\dbproc

inlcude debug.inc and inlcuelib debug.lib

    mov eax,10101010101010101101010101010101b ;just random value for test
mov ecx,8 ;8 because I want to check 8 bits, so I'll loop it 8 times
mov ebx,0 ;number of starting bit

TEST_BITS:
push ecx

bt eax,ebx ;that should return value of ebx bit in eax to CF
jc one
jnc zero

zero:
PrintText "ZERO"
jmp skip_one

one:
PrintText "One"

skip_one:
inc ebx
pop ecx
dec     ecx
    jnz     TEST_BITS
;loop TEST_BITS
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

qWord

The problem is, that API-calls commonly overwrite all register except for EDI,ESI and EBX, which must be preserved by callee.
You must preserve EAX when calling an API function, as you have done it with ECX.
FPU in a trice: SmplMath
It's that simple!

Gunner

~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

daniek91

YES  ! :bg

I've spend 3 days looking for an answer and You've solved it in 3 minutes !
Thank You very, very, very much  :cheekygreen:
Now I'll know where I can find help if anything comes up while working on my project  :U


Best regards,
Daniel