flat assembler
Message board for the users of flat assembler.

Index > Main > Trouble with byte

Author
Thread Post new topic Reply to topic
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
It's me... ic2. I had to re-register because it said I forgot my password when i did not. I no longer own my old e-mail address and that was about it and had nothing to do with my known password. After hours of trying and force to wait 30 minutes so many times ... anyway...


I'm having trouble trying to replace the last byte in a dword that will change it value. I founded in the manual that I can use movsx. The problem is I can't figure out how to do such a thing inside the registers only to speed things up.

Could someone show me how to do this with the shortest code possible with decent speed and also with the fastest code possible where size don't matter.

Thanks in advance



Code:
format PE GUI 4.0
entry start

  include '\fasm\include\win32a.inc'

  section '.code' code readable executable

        start:

;  Here I tried lots of other ways to 
;  use registers only but don't know how to make it work.  
;  mov   eax, TEMP_1
;   mov [eax + 3],  [szNumber_Four]

;invoke MessageBox,0,eax,0,0

;  Here I learn how to do it by copying the register 
;  content into  a buffer.  It works but this would
;  be a long way around and slow.

mov   ebx, [TEMP_1]
 mov [TempBuffer], ebx
  movsx edx, byte [szNumber_Four]
    mov   [TempBuffer + 3], edx

invoke MessageBox,0,TempBuffer,0,0
invoke ExitProcess,0

;  ---------------------------------------------
;  ---------------------------------------------     .DATA
   section '.data' data readable writeable

   szNumber_Four    db  "4"

 align 4

  TempBuffer   dd        1

  TEMP_1       dd   "1230"
;  ---------------------------------------------
;  ---------------------------------------------
   section '.idata' import data readable writeable

   library kernel32, 'KERNEL32.DLL',\
             user32, 'USER32.DLL'

   include '\fasm\include\api\kernel32.inc'
   include '\fasm\include\api\user32.inc'     
[/code]
Post 26 Jun 2008, 22:59
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
Code:
value dd 33221100h
...
mov byte[value+3],44h
...
;now, [value] is equal to 44221100h
    
Post 26 Jun 2008, 23:14
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
movzx edx,bl ; register byte to dword

Upper three bytes of EDX will be zero.

Num dd "0123"

mov edx,[Num]
mov dl,"4"
mov [Num],edx ; "0124"

or

mov edx,[Num]
bswap edx
mov dl,"4"
bswap edx
mov [Num],edx ; "4123"

It's difficult to understand what you want exactly.

_________________
¯\(°_o)/¯ unlicense.org
Post 26 Jun 2008, 23:16
View user's profile Send private message Visit poster's website Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
Thanks guys

edfed, I always wondered how you convert a string like 1230 to 33221100h. Would I use a string2Dword procedure. That's something else I will look into after I get past this problem.

What I did for days was:

mov byte [Num + 3], "4"
results as expected 1234

I knew how to do this already. But I been trying to use an offset value (a one byte string from data section). I see this may be impossible so I'm wondering if there's a macro that can change or control what can be in a immediate value "4" with-out making code section writeable. But beggar can't be choosy.

Straight from the .data section do not work:

mov byte [Num + 3], string
error = value out of range

If this can be solved by a macro or something else it would be great. I like it because of size.
Quote:
It's difficult to understand what you want exactly.

BitRAKE, The manuals and samples i seen over time say no ... but I know there got to be work-around so I'm just trying things out and want to know how to do the same as above using only registers with fewer lines as possible. This was my first objective.

I got a lot of ways to do this with a string like EndofString proc but just to change a single byte at the end of a dword is not in the manuals as far as I know. It speaks of word, 2 bytes or dword.

Your code change the first byte in a dword. I'm trying to change the last byte. My code with the zero threw you off.

I want to do the same as above with edfed reminder code but I also want to know how to do the whole operation with the dword already in the registers waiting for the single byte string from the data section to be attached. Sound so simple but yet no mnemonic exist for this little thingy. Is there any hope???

mov ebx, [Num] (1237) or (123 )
mov eax, string (4)
mov [ebx + 3 + pop bitRAKE magic],ahhh

results ebx or eax = 1234

Smile Smile
Post 27 Jun 2008, 02:32
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
mov eax,[YourDword-1]
shrd eax,dword [YourByte],8

...there are many ways...

mov eax,[YourDword]
movzx edx,[YourByte]
and eax,$FFFFFF
bswap edx
add eax,edx ; or eax,edx

There isn't a single instruction for registers unless SHRD can be made to work.

_________________
¯\(°_o)/¯ unlicense.org
Post 27 Jun 2008, 03:15
View user's profile Send private message Visit poster's website Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
2 lines Wow!!! Thanks bitRAKE. This is going to take me far with asm. I will be reading and doing much this weekend. Thanks again
Post 27 Jun 2008, 03:56
View user's profile Send private message Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
i can't see where i'm going wrong here. I get a empty messagebox.

Code:
format PE GUI 4.0 
entry start 

  include '\fasm\include\win32a.inc' 

  section '.code' code readable executable 

        start: 
; ...................................  not working
;  mov eax,[TEMP_1] 
;  shrd eax,dword [string],8
;invoke MessageBox,0,eax,0,0 

; ...................................  empty MBox
  mov eax,[TEMP_1] 
  mov edx,string
  shrd eax,dword edx,8

invoke MessageBox,0,eax,0,0 
invoke ExitProcess,0 

;  --------------------------------------------- 
;  ---------------------------------------------     .DATA 
   section '.data' data readable writeable 

   string    db  "D" 

 align 4 

  TEMP_1       dd   "ABCZ" 
;  --------------------------------------------- 
;  --------------------------------------------- 
   section '.idata' import data readable writeable 

   library kernel32, 'KERNEL32.DLL',\ 
             user32, 'USER32.DLL' 

   include '\fasm\include\api\kernel32.inc' 
   include '\fasm\include\api\user32.inc'     
Post 27 Jun 2008, 05:02
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
bitRAKE wrote:
mov eax,[YourDword-1]

I know you would have to be unlucky, but that could cause an access violation.

Code:
    invoke MessageBox,0,eax,0,0    

MessageBox needs a pointer to a string in EAX, not just a number.
Post 27 Jun 2008, 05:19
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
okay, it's a little different - this works:
Code:
include 'win32wx.inc'

.end start

start:
        mov eax,[TEMP-1]
        shld dword [string],eax,24

        invoke MessageBoxA,0,string,0,0
        invoke ExitProcess,0


string db "D",0,0,0,0

    align 4

TEMP dd "ABCZ"    

_________________
¯\(°_o)/¯ unlicense.org
Post 27 Jun 2008, 05:23
View user's profile Send private message Visit poster's website Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
Yes it does. I see I got a lot to learn. Searching like crazy for the pass few hours lead me to places like this...
http://board.flatassembler.net/topic.php?t=6533 Math etc... How do you guys handle it all and all to come.

Thanks again bitRAKE. I am happy for that one byte for the next few weeks Smile. No way would i have figure that out any time soon. I been on this for weeks going no where. It's hard to give up.

PS:Staff... I wonder what happen to my password. Easy as iic2 and never changed by me. Hello sinsi. I think that's where the bad luck begun than came 2 lines of the meanest code ever that is about to make a true assembler out of me ,,, Smile
Post 27 Jun 2008, 06:30
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
Code:
    mov eax,[TEMP_1]
    mov dl,[string]
    bswap eax
    mov al,dl
    bswap eax    


Sorry bitRAKE, I just don't like the idea of going [var-1]
Code:
virtual at edi
    mydword rd 1
end virtual
...
    call [VirtualAlloc]
    mov edi,eax
...
    mov eax,[mydword-1]
    crash...    
Post 27 Jun 2008, 07:30
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
sinsi, you are correct - there should be some kind of warning with that usage. I was merely attempting to answer the problem in as lazy a fashion as possible.

iic2, for me it is an adventure - a journey of discovery. Every instruction another piece to a puzzle with an undefined picture. Don't settle - never become content with what you have become.

_________________
¯\(°_o)/¯ unlicense.org
Post 27 Jun 2008, 13:34
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
Code:
;"1230" to 33221100h (which in memory resides like 00h,11h,22h,33h
mov eax,"1230"
sub eax,30303030h ; 00030201h
imul eax,1100h ; 33221100h
    

What you are asking is a bit overly complicated. You may also need a BSWAP there if your order needs to be different.
Post 29 Jun 2008, 22:38
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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.

Powered by rwasa.