flat assembler
Message board for the users of flat assembler.

Index > Main > Request some help about conditional jump depending of bit

Author
Thread Post new topic Reply to topic
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
Sorry if I ask some basic but my knowledge in asm programming is low.
I'm trying something and for the moment I'm blocked.

I need to read something from memory then when value reach needed condition to go next.

Size is dword,and have this structure:
31:8 reserved
7 conditional (must be 0 for continue)
6:4 reserved
3 conditional (must be 0 for continue)
2:1 reserved
0 conditional (must be 0 for continue)

So just bits 0 3 and 7 is conditional for me,others may have any value but is important to not go to next step until bits 0 3 and 7 are not 0

Will be very helpfull if this dword value can be displayed onto display in case something go wrong to help me to localize the problem.

I have tried few combination like

demo:
test [fs:ebx+120h], 80h
jnz demo

[fs:ebx+120h] is address what I need to read and wait to become needed value.
That's for bit 7 but since bits 6 4 2 and 1 can have any value I think is not ok.

And another case.
on another address bits 3:0 can have any value but I need to wait a liitele and in case of value 1h or 3h to continue for other values to wait 1-3 seconds then if values become 1h or 3h continue else jump to end.
Like before is very useful if this value will be displayed on screen.

Could somebody tell me or assiste me to do this?

Since english is not m native language I hope I was clearly enough.
Thanks.
Post 26 Jun 2010, 00:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17473
Location: In your JS exploiting you and your system
revolution
Code:
test [fs:ebx+120h],10001001b ;bits 7, 3 and 0 are tested
jz .continue    
Post 26 Jun 2010, 01:39
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
test dword [fs:ebx+120h], (1 shl 0) or (1 shl 3) or (1 shl 7) ; or just ", 89h"    


Once all those bits are zero the ZF flag will turn on so the jnz will not jump to "demo" again.

Here a macro that can test for zero all the bits you may want:
Code:
; Result in ZF
macro all_zero operand, [bit*]
{
common
local mask
        mask = 0

forward
        mask = mask or (1 shl bit)
        if bit < 0 | bit > 63 ; fasm will catch the rest of the errors when assembling TEST
           err 'out of range' 
        end if

common
        test operand, mask
}

;Usage example
all_zero dword [fs:ebx+120h], 7, 0, 3    
Post 26 Jun 2010, 01:59
View user's profile Send private message Reply with quote
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
revolution wrote:
Code:
test [fs:ebx+120h],10001001b ;bits 7, 3 and 0 are tested
jz .continue    


I'll try this becouse seems more simple.

I have tried but at compile I get error
Code:
test[fs:ebx+120h],10001001b
operand size not specified    


I forget to tell that I run this in a PCI option rom,after bios end POST and start bootloader.

I also have one question.
There ia a error register and I need to clear.
If bit is 1 signaling a error status I need to write 1 at that bit to clear error.writing 0 have no efect.
I try to read then write value back but seems isn't working
Code:
        mov eax,[fs:ebx+130h]
        mov [fs:ebx+130h],eax         


is that ok?

Thanks for fast response.
Post 26 Jun 2010, 02:33
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:


I have tried but at compile I get error

Use "test dword [fs:ebx+120h],10001001b"

Quote:

is that ok?

Yes, but are you sure you have to write one instead of zero? Maybe you're supposed to do this:
Code:
; I'm supposing it is bit0, change as you need
and dword [fs:ebx+130h], (-1) xor 1    
?
Post 26 Jun 2010, 02:54
View user's profile Send private message Reply with quote
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
In datasheet specify that
Clear the PxSERR register, by writing ā€˜1sā€™ to each implemented bit location
If no error is 0 and error is 1 then you need to write 1 to each bit is 1 to clear them

How can I read dword at [fs:ebx+120h] and print it on screen?
I have searched but most finds was for text display or too complex for me to adapt to my need.

Thanks again.
Post 26 Jun 2010, 03:02
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Well, perhaps the device is sensible to unimplemented bit locations and the value you read you are not supposed to write it back. Maybe you should use "mov dword[fs:ebx+130h], NUMBER_WITH_IMPLEMENTED_BITS_ON"

Another problem could be that the CPU's MTTR are not covering the device properly and hence, the memory accesses end up cached instead of forwarded to the device as soon as you make them.

Quote:
How can I read dword at [fs:ebx+120h] and print it on screen?
Does Int10h work in your execution environment?
Post 26 Jun 2010, 03:16
View user's profile Send private message Reply with quote
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
Quote:
Does Int10h work in your execution environment?


Not sure, I suppose is working.
right now I'm using this
Code:
     push es
     push ax
     mov ax,0xB800
       mov es,ax
   mov byte[es:0x9C],'S'
 pop ax
      pop es
    

with different caracter like a marker to see where is freezing in some cases.
Post 26 Jun 2010, 03:27
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
print_hex: ; DX = Row ; AX = Col ; ECX = NUMBER (Assuming 80x25 mode)
        pushad
        push    es

        push    $B800
        pop     es

        imul    di, dx, 80
        add     di, ax
        shl     di, 1

        mov     edx, ecx
        mov     ecx, 8
        mov     ah, 7 ; GRAY FONT; BLACK BACKGROUND

.writeNibble:
        rol     edx, 4
        mov     si, dx
        and     si, $F
        mov     al, [cs:.lut+si]
        stosw
        loop    .writeNibble

        pop     es
        popad
        ret
.lut db '0123456789ABCDEF'    


BTW, I think you are working with AHCI? Is your BIOS supporting it? In case it is not then you should really check if the HBA is mapped in a memory region the processor doesn't apply any caching.

[edit]Added shl di, 1[/edit]


Last edited by LocoDelAssembly on 26 Jun 2010, 19:05; edited 1 time in total
Post 26 Jun 2010, 17:54
View user's profile Send private message Reply with quote
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
Yes is about AHCI.But BIOS not supporting.
HBA is mapped to E0200000h

Sorry if is a silly questions but how I use this
how I set what memory address to print or I need to call print_hex but then from where is taken address to read.

Thanks for help.
Post 26 Jun 2010, 18:49
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
To print 12345678 on the center of the screen use this:
Code:
mov ecx, 12345678h
mov dx, 25/2
mov ax, 80/2 - 8/2
call print_hex    


To print some memory then simply replace the "mov ecx, 12345678h" with, say, "mov ecx, [fs:ebx+130h]".

PS: Note that I've edited my previous post to fix a bug
Post 26 Jun 2010, 19:05
View user's profile Send private message Reply with quote
gabiz_ro



Joined: 20 Feb 2010
Posts: 67
gabiz_ro
Thank you.
Is working fine.
Now I hope I have more chance to initialize controller in ahci mode.
Post 26 Jun 2010, 20:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.