flat assembler
Message board for the users of flat assembler.
Index
> Main > String to Integer and vice versa Goto page Previous 1, 2 |
Author |
|
Tyler 08 Dec 2009, 00:13
Quote:
Wouldn't I just, Code: ;eax = current set of chars ;ebx = offset ;ecx = total str_to_int: xor eax, eax xor ebx, ebx xor ecx, ecx @@: mov eax, [str + ebl] add ebl, 4 cmp eal, 0 je @f cmp eah, 0 je @f ;I don't know how to check in the upper half of eax sub eax, '0000' imul ecx, 1000 add ecx, eax jmp @b @@: mov [int], ecx retn Or do you mean process the whole thing without jumping. Would this work? |
|||
08 Dec 2009, 00:13 |
|
LocoDelAssembly 08 Dec 2009, 00:46
Tyler, supposing you fix those unexistent registers it will still not work. For instance lets suppose EAX is '1234', when you substract '0000' it will be 1*2^24 + 2*2^16 + 3*2^8 + 4*2^0 (i.e. 16,909,060) which is a number much bigger than 1234 and then you'll multiply it by 1000 which will make it way much bigger.
To solve this problem you'll need to either learn MMX (or SSE), or use some trick to process the characters in parallel. (Don't bother for now, besides, it is not clear if you'll actually get better performance) |
|||
08 Dec 2009, 00:46 |
|
Tyler 08 Dec 2009, 01:50
Borsuc wrote:
I was thinking the same. LocoDelAssembly wrote:
What nonexistent regs? As for it not working, I totally agree, I had the concept completely wrong. |
|||
08 Dec 2009, 01:50 |
|
LocoDelAssembly 08 Dec 2009, 02:00
There is no ebl, eal and eah registers, I guess you mean bl, al, and ah which them do exist. But then there is another problem, you can't use [str+bl], not only because "str" is a reserved symbol, but also because you can't use 8-bit registers for addressing.
|
|||
08 Dec 2009, 02:00 |
|
Tyler 08 Dec 2009, 03:40
@LocoDelAssembly: I learned that you could access the lower halves of e(a-d)x like they were (a-d)x in my very early asm research. It was a tutorial I dled from some obscure website, apparently I should reconsider my sources. This was before I found Fasm, of course.
btw, did you know Fasm is underlined as misspelled, that's messed up! |
|||
08 Dec 2009, 03:40 |
|
kohlrak 08 Dec 2009, 19:18
Ok, your sources aren't completely wrong.
Firstly, the registers are all swapped. Because of this, bit 7 is the leftmost bit in ALL sizes of registers (i forget whether this is called big endian or little endian...). Now, with that in mind, an excerpt from my AFS project: Code: ;+----------EAX----------+ ;| AX | unnamed | ;| AL | AH | unnamed | ;+-----------------------+ Note that is just 1 register. Edit: The reason i depicted the register like this makes it easier to understand that "dd 0x01234567" is the same as "db 0x67, 0x45, 0x23, 0x01." This is important to remember and not to screw up. Last edited by kohlrak on 08 Dec 2009, 19:23; edited 1 time in total |
|||
08 Dec 2009, 19:18 |
|
Borsuc 08 Dec 2009, 19:20
AL is the lowest byte though, and AX the lowest word. You can't access the higher words or bytes directly.
Also kohlrak that diagram is confusing, it should be reversed. After all, "shifting right" by 24 shifts the highest byte towards AL... which should be on the right. |
|||
08 Dec 2009, 19:20 |
|
LocoDelAssembly 08 Dec 2009, 20:08
Ups I messed up with endianness too, with Tyler's method the actual value for string '1234' without the multiplication part would be 67,305,985, not 16,909,060.
|
|||
08 Dec 2009, 20:08 |
|
kohlrak 08 Dec 2009, 20:19
Now you see why i made that confusing diagram. I'd rather have not had to, but as you see, it's necessary.
|
|||
08 Dec 2009, 20:19 |
|
edfed 08 Dec 2009, 21:04
a very little idea.
use macro to make a prefix. for exemple, force access to upper words and bytes of registers. example: Code: heax mov bl,al ;will use al as a byte from hword hreg in general to access any wanted register upper word. transparentlly making: ROR %reg,16 %inst %reg1,%reg ROR %reg,16 or maybe a more complex thing like adding hax,hal,hah as upper part in instrutions,and macro will make the right stuff. |
|||
08 Dec 2009, 21:04 |
|
Tyler 08 Dec 2009, 22:19
Borsuc wrote:
This was my understanding. I was just messed up in the fact I thought ax and eax were separate. That's why I thought I had to use the "e" in, I wrote:
|
|||
08 Dec 2009, 22:19 |
|
Tyler 10 Dec 2009, 03:41
I figured out the first part of my question(with help, of course), but does anyone have any light to shed on integer to string?
|
|||
10 Dec 2009, 03:41 |
|
LocoDelAssembly 10 Dec 2009, 03:52
Look at these threads:
http://board.flatassembler.net/topic.php?t=5302 << Simple ways http://board.flatassembler.net/topic.php?t=3924 << Complex methods |
|||
10 Dec 2009, 03:52 |
|
kohlrak 10 Dec 2009, 03:52
Integer to string? Divide by 10, add '0.' Be sure to go backwords though. Perhaps using the direction flag and the stosb function.
|
|||
10 Dec 2009, 03:52 |
|
Borsuc 10 Dec 2009, 19:52
Take the remainder of the division by 10 and add '0' and output that, then use the divided number (not remainder) to continue to next loop. And yes you have to do it backwards.
Division by constants can be converted to multiplications by "magic numbers" (much faster, muls compared to divs, but it requires some math to get those magic numbers to multiply with). One method is to use fixed-point to find out the 'reciprocal' (in integers) of the 10 constant, multiply by that, shift appropriately (truncates result), then multiply by 10 (via 'lea' is faster, see my code on this topic about ascii to int, same principle) and subtract the difference between original and this one (truncated) yields the remainder. Of course it's actually better to get the remainder directly with the multiplication but it's a bit more advanced so I'll leave it to you to research it yourself. Here's a fixed point article: http://x86asm.net/articles/fixed-point-arithmetic-and-tricks/index.html _________________ Previously known as The_Grey_Beast |
|||
10 Dec 2009, 19:52 |
|
DOS386 11 Dec 2009, 01:28
Tyler wrote: I figured out the first part of my question(with help, of course), but does anyone have any light to shed on integer to string? See above, FASM IDE sources, and here: http://board.flatassembler.net/topic.php?t=8670 |
|||
11 Dec 2009, 01:28 |
|
Tyler 11 Dec 2009, 03:50
DOS386 wrote:
It's not that I'm too lazy to read it, it's that I don't understand it. I read through "PARSER.INC." It's just so massive that I never found what I was looking for. |
|||
11 Dec 2009, 03:50 |
|
DOS386 11 Dec 2009, 10:40
Not massive: http://board.flatassembler.net/topic.php?t=8670
|
|||
11 Dec 2009, 10:40 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.