Addition question...

If I use the following code:

[code]
mov al, 255
inc al
[/code]

Would eax be 0h00000000 or 0h00000100?

--------------------------------------------
I will bend your mind with my spoon...

Comments

  • : If I use the following code:
    :
    : [code]
    : mov al, 255
    : inc al
    : [/code]
    :
    : Would eax be 0h00000000 or 0h00000100?
    :
    : --------------------------------------------
    : I will bend your mind with my spoon...
    :
    1. EAX will save its 24 bits BEFORE AL if that is what you asking, so if EAX was 12345600h then it will be same 12345600h after INC AL.

    2. For questions like that you can use debugger - you can type the ASM code into it and perform a few steps watching the registers...

    3. The opcodes will affect only bits of the register specified in that command: for example if you will do:

    mov al, 255
    inc ax ; this WILL actually transfer/add this overflowing bit into but #8 of AX.


  • Now if I use 32-bit registers, take EAX for example, how do I access the lower bits? Can use code like "push ax" and "push eax" in the same peice of code?

    --------------------------------------------
    I will bend your mind with my spoon...

  • : Now if I use 32-bit registers, take EAX for example, how do I access the lower bits? Can use code like "push ax" and "push eax" in the same peice of code?
    :
    : --------------------------------------------
    : I will bend your mind with my spoon...
    :
    you can not access ONLY the lower bits of EAX in a DIRECT way: there is no L(ower)AX or something like that ... you could rotate the registers and use ax and rotate again ...
    like this:

    [code]
    rol eax, 8
    ... do something with ax ...
    rol eax, 8
    [/code]

    now you did not affect the original ax, but the lower bits ...

    About the push stuff : yes you can ! you can even use 'push al' together with them :-)

    SUSE LINUX 7.3 PRO - The world starts behind windows

  • : Now if I use 32-bit registers, take EAX for example, how do I access the lower bits? Can use code like "push ax" and "push eax" in the same peice of code?
    :
    : --------------------------------------------
    : I will bend your mind with my spoon...
    :
    :
    Clarify, please, what is the problem?
    You can use any registers (EAX, AX, AL, AH) in 32-bit code. As you can see you can access all the lower bits immediately with other registers. Except the middle bits in EAX itself:
    [code][code=000000][color=21C6FF]
    00000000 00000000 00000000 00000000
    | | | |
    EAX | AX |
    | | |
    | AH AL
    ?
    only here you can't access...
    [/color][/code][/code]
    You can access them - like use them in non-math way, but you cannot use them in math and hope they will affect the neighbouring regs - just as I pointed out earlier.

    And of course [red]do not do this:[/red]
    [code][code=000000][color=21C6FF]
    push ax
    pop eax
    [/color][/code][/code]
    Your STACK will be damaged by this operation. With the stack you have to POP the same number of bits you PUSHED, like:
    [code][code=000000][color=21C6FF]
    push dx ; 16-bits in
    push ax ; 16-bits in
    pop eax ; 32-bits out
    [/color][/code][/code]
    This code is fine.

    And a last point - if you trying to keep EVERYTHING in regs and use shifts and OR/AND to extract/set your variables - you will only end up with a slower code. The better way to do it, just use local vars in your procedures:
    [code][code=000000][color=21C6FF]
    Foo Proc
    local dwVar1:dword, dwVar2:dword=VarsRoom
    enter VarsRoom, 0 ; Allocate stack vars

    ; ...
    mov dwVar1, eax
    mov ecx, dwVar2
    ; ...
    leave ; Clean up stack vars
    ret
    Foo EndP
    [/color][/code][/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories