flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
NEASM
(i haven't found a good manner to do this in C as well)
|
|||
![]() |
|
revolution
One thing to realise is that the register EAX is 32-bits wide, so it can only hold a maximum of 4 bytes. So assuming you want just 4 bytes you can do this:
Code: mov ecx,'hel' ;ECX=0x006c6568 mov edx,'l' ;EDX=0x0000006c ;... mov eax,edx ;EAX=0x0000006c shl eax,24 ;EAX=0x6c000000 or eax,ecx ;EAX=0x6c6c6568 = 'hell' |
|||
![]() |
|
redsock
lest we forget AMD64 and do the same:
Code: mov ecx, 'hel' mov edx, 'lo' mov eax, edx shl rax, 24 or rax, rcx ![]() |
|||
![]() |
|
NEASM
revolution wrote: One thing to realise is that the register EAX is 32-bits wide, so it can only hold a maximum of 4 bytes. So assuming you want just 4 bytes you can do this: Thanks. But, for concatenate strings like this? Code: buffer db 'Hello', 0 buffer2 db ', World!', 0 buffer3 rb 100 ..... mov ecx, [buffer] mov edx, [buffer2] ..... ; something mov [buffer3], eax |
|||
![]() |
|
DimonSoft
NEASM wrote: Thanks. But, for concatenate strings like this? First describe how would you store the resulting string in 4 bytes. |
|||
![]() |
|
Walter
The C runtime functions can be used if you are using pointers to strings.
Code: ;************** ;* Concat.asm * ;************** format pe console 4.0 entry start include 'win32a.inc' section '.data' data readable writeable strPart1 db 'Hel',0 strPart2 db 'lo.',0 strFormat db '%s',13,10,0 strResult rb 128 section '.code' code readable executable start: cinvoke strcpy,strResult,strPart1 cinvoke strcat,strResult,strPart2 cinvoke printf,strFormat,strResult invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ strcpy,'strcpy',\ strcat,'strcat' |
|||
![]() |
|
DimonSoft
C runtime functions should be supplied with obligatory warning about possible security vulnerabilities (buffer overflow) caused by insufficient buffer sizes (in case source string lengths are not known in advance) which has been the problem for C/C++ programs for a few decades now. Not sure if msvcrt.dll provides safe versions.
P.S. The functions still don’t let one put an arbitrary string into 4-byte register. |
|||
![]() |
|
NEASM
DimonSoft wrote:
Excuse me, i'm not so expert. |
|||
![]() |
|
DimonSoft
NEASM wrote:
It’s not about expertise, it’s about proper task formulation and common sense. |
|||
![]() |
|
ManOfSteel
Perhaps NEASM wants eax to hold the pointer to the resulting string, not the actual resulting string?!
|
|||
![]() |
|
DimonSoft
ManOfSteel wrote: Perhaps NEASM wants eax to hold the pointer to the resulting string, not the actual resulting string?! Which is the most obvious case but that contradicts with NEASM wrote: (ie: ECX = "hel"; EDX = "lo"; EAX = "hello", for example) |
|||
![]() |
|
Furs
NEASM wrote: Sorry for the trouble, 'hel' is 3 bytes, but 'hello' is 5 bytes so it won't fit. What you ask for is impossible. |
|||
![]() |
|
revolution
Furs wrote: EAX is 4 bytes. |
|||
![]() |
|
DimonSoft
revolution wrote:
Or we could use Huffman encoding with custom frequency table. 14 bits ought to be enough for greeting (and even zero-termination). |
|||
![]() |
|
revolution
At least two ways to encode in 14 bits:
Code: l = 00 e = 01 h = 10 o = 110 _ = 111 ------- 14 bits Code: l = 0 e = 100 h = 101 o = 110 _ = 111 ------- 14 bits |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2019, Tomasz Grysztar.
Powered by rwasa.