hee folks
my question is how to get a bit to a buffer. eax contains a dword and i have to get every bit from this dword in a buffer. let me show you a example.
eax = 0000A0B6
buffer 1 should get; A
buffer 2 should get; 0
buffer 3 should get; B
buffer 4 should get; 6
any help?
asm getting bit from dword
Page 1 of 111 Replies - 1010 Views - Last Post: 21 August 2012 - 03:28 PM
Replies To: asm getting bit from dword
#2
Re: asm getting bit from dword
Posted 17 August 2012 - 04:18 PM
You need to isolate the low byte (4 bits) get it, and rotate right by 4 to get next number.
Output:
al = 06
al = 0B
al = 00
al = 0A
mov ecx, 16 ; test number is 16 bits, change to 32 for a full DWORD
mov esi, 0A0B6H ; your test numbewr
GetByte:
mov eax, esi ; move number to eax
and eax, 0FH ; get least significant byte (4 bits)
; Number is in al now, do what you want with it here.
PrintHex al
sub ecx, 4 ; decrease our counter
ror esi, 4 ; rotate the bits in the number right by 4 to get next number
jnz GetByte ; is counter 0? If not, get next number
Output:
al = 06
al = 0B
al = 00
al = 0A
#3
Re: asm getting bit from dword
Posted 18 August 2012 - 03:05 AM
thanks gunnerinc
but actually i want the ascii value, not hex value.
so when al = 06, i want the ascii 6, which is 36 in hex.
another example when al = 0A, i want the ascii A (41h)
is this possible?
but actually i want the ascii value, not hex value.
so when al = 06, i want the ascii 6, which is 36 in hex.
another example when al = 0A, i want the ascii A (41h)
is this possible?
#4
Re: asm getting bit from dword
Posted 18 August 2012 - 09:18 AM
what? I'm not sure your defining this very well. what is it that your trying to do? I'm almost sure there is better way.
#5
Re: asm getting bit from dword
Posted 18 August 2012 - 09:30 AM
See the comment I left in the code
The CPU does cannot tell the difference between hex, dec, oct, ascii or whatever. It sees 0000A0B6 as 1010000010110110 (actually it sees it in Little Endian order), it is up to you to do as you want.
See the differece between the number and the ASCII of the number? Now, how would you convert a number to ASCII?
Quote
; Number is in al now, do what you want with it here.
The CPU does cannot tell the difference between hex, dec, oct, ascii or whatever. It sees 0000A0B6 as 1010000010110110 (actually it sees it in Little Endian order), it is up to you to do as you want.
0 1 2 3 4 5 6 7 8 9 < decimal numbers 48 49 50 51 52 53 54 55 56 57 < ASCII code for numbers
See the differece between the number and the ASCII of the number? Now, how would you convert a number to ASCII?
#6
Re: asm getting bit from dword
Posted 18 August 2012 - 12:01 PM
i hope im able to explain it cleary what i want to do
i got a constant string like 1234567890 and i got some random characters, after doing some math with these random charaters the output is a dword like 0000A0B6.
then i want to replace the output to some positions of the constant string.
here is example
- constant string == 1234567890
- output == 0000A0B6
- replace the output to a constant position of the constante string, like ; A20456B896
i got a constant string like 1234567890 and i got some random characters, after doing some math with these random charaters the output is a dword like 0000A0B6.
then i want to replace the output to some positions of the constant string.
here is example
- constant string == 1234567890
- output == 0000A0B6
- replace the output to a constant position of the constante string, like ; A20456B896
#7
Re: asm getting bit from dword
Posted 18 August 2012 - 03:10 PM
0000A0B6 is not a DWORD, it is a STRING. I already said the CPU only knows 1's and 0's, how YOU see it displayed is from a conversion.
What is a "constant" string? I am not up on the High Level terminology. How is this string defined? Data defined as a constant in Assembly CANNOT be changed, you would need to copy this string to a buffer then do what you want with it.
Is this output string always going to be 4 bytes long, or a full 32 bits?
Is the "A", "0", "B", and "6" always going to be in the same insertion point of the string?
The simplest way (the easiest to understand) would be to use 3 pointers.
1. to the buffer to hold the final string
2. to the "constant" string
3. to the "output" string.
We could do it this way, without a loop:
Ouput:
edi = A20456B896
What is a "constant" string? I am not up on the High Level terminology. How is this string defined? Data defined as a constant in Assembly CANNOT be changed, you would need to copy this string to a buffer then do what you want with it.
Is this output string always going to be 4 bytes long, or a full 32 bits?
Is the "A", "0", "B", and "6" always going to be in the same insertion point of the string?
The simplest way (the easiest to understand) would be to use 3 pointers.
1. to the buffer to hold the final string
2. to the "constant" string
3. to the "output" string.
We could do it this way, without a loop:
.data
conststring db "1234567890", 0
stringlen equ ($ - conststring) - 1
output db "A0B6", 0
outputlen equ ($ - output) - 1
.data?
lpBuffer db outputlen + stringlen + 1 dup (?)
.CODE
start:
mov esi, offset conststring
mov edi, offset lpBuffer
mov ebx, offset output
; "A"
mov al, byte ptr [ebx]
mov byte ptr [edi], al
inc ebx
inc edi
; 2
inc esi
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi
; "0"
mov al, byte ptr [ebx]
mov byte ptr [edi], al
inc edi
inc ebx
; 45
inc esi
mov ax, word ptr [esi]
mov word ptr [edi], ax
inc edi
inc edi
; 6
inc esi
inc esi
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc edi
; "B"
mov al, byte ptr [ebx]
mov byte ptr [edi], al
inc edi
inc ebx
; 89
inc esi
inc esi
mov ax, word ptr [esi]
mov word ptr [edi], ax
inc edi
inc edi
; "6"
mov al, byte ptr [ebx]
mov byte ptr [edi], al
lea edi, lpBuffer
PrintStringByAddr edi
push 0
call ExitProcess
Ouput:
edi = A20456B896
#8
Re: asm getting bit from dword
Posted 18 August 2012 - 04:17 PM
oky string then instead of dw 
constant string means not changeable, defined as conststr db "1234567890",0
the output is not always 4 bytes long, but for now to keep it easy, its yes, always 4 bytes long.
yes its always the same insertion point of the string.
im gonna try this code and let you know if i can solved the problem
thank you sir again
constant string means not changeable, defined as conststr db "1234567890",0
the output is not always 4 bytes long, but for now to keep it easy, its yes, always 4 bytes long.
yes its always the same insertion point of the string.
im gonna try this code and let you know if i can solved the problem
thank you sir again
#9
Re: asm getting bit from dword
Posted 18 August 2012 - 04:51 PM
Strings in the .data section (or any data) can be modified as you would data in the .data? section.
Strings and data defined in the .const section CANNOT be modified, if you try your program will segfault.
Strings and data defined in the .const section CANNOT be modified, if you try your program will segfault.
#10
Re: asm getting bit from dword
Posted 20 August 2012 - 03:16 PM
for a unkown reason when i use your code the winasm studio will crash. im sure that i corrected all lines. i can compile it succesfully.
and i dont understand why you using StrLen, i guess to locate the position in which the byte should be replaced from the constant string?
if so then i think that code you posted with strLen is not needed because the positions are constant so will not change.
1 , 3, 7 ,9 are the positions, so i think its better to write the code for replacing like this:
lea edi, offset ConStr ; load 1234567890
mov al, byte ptr [ebx] ; A
mov byte ptr [edi+1], al
mov al, byte ptr [ebx] ; 0
mov byte ptr [edi+3], al
mov al, byte ptr [ebx] ; B
mov byte ptr [edi+7], al
mov al, byte ptr [ebx] ; 6
mov byte ptr [edi+9], al
and i dont understand why you using StrLen, i guess to locate the position in which the byte should be replaced from the constant string?
if so then i think that code you posted with strLen is not needed because the positions are constant so will not change.
1 , 3, 7 ,9 are the positions, so i think its better to write the code for replacing like this:
lea edi, offset ConStr ; load 1234567890
mov al, byte ptr [ebx] ; A
mov byte ptr [edi+1], al
mov al, byte ptr [ebx] ; 0
mov byte ptr [edi+3], al
mov al, byte ptr [ebx] ; B
mov byte ptr [edi+7], al
mov al, byte ptr [ebx] ; 6
mov byte ptr [edi+9], al
#11
Re: asm getting bit from dword
Posted 21 August 2012 - 03:25 PM
figured out now it works ! thanks you very much sir! you are a great contribution to asm language
#12
Re: asm getting bit from dword
Posted 21 August 2012 - 03:28 PM
Sometime the best answer is to not answer at all :-) You learn how to do it on your own! Feels better to, no? Glad you are starting to understand it!!!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|