flat assembler
Message board for the users of flat assembler.

Index > Windows > Can anyone help me convert nasm code to fasm

Author
Thread Post new topic Reply to topic
3371574870



Joined: 15 Sep 2020
Posts: 5
Location: null
3371574870
or we can say:
"123" -> starting from 1

1 + 0 * 10 = 1
2 + 1 * 10 = 12
3 + 12 * 10 = 123

This will match to atoi function as below:

atoi:

push %ebx # preserve working registers
push %edx
push %esi

mov $0, %eax # initialize the accumulator
nxchr:
mov $0, %ebx # clear all the bits in EBX
mov (%esi), %bl # load next character in BL
inc %esi # and advance source index

cmp $'0', %bl # does character preceed '0'?
jb inval # yes, it's not a numeral jb:jump below
cmp $'9', %bl # does character follow '9'?
ja inval # yes, it's not a numeral ja:jump above

sub $'0', %bl # else convert numeral to int
mull ten # multiply accumulator by ten. %eax * 10
add %ebx, %eax # and then add the new integer
jmp nxchr # go back for another numeral

inval:
pop %esi # recover saved registers
pop %edx
pop %ebx
ret






Rolling Eyes
This is a subroutine about string to int

Any help would be appreciated!

source address´╝Ü
https://stackoverflow.com/questions/19461476/convert-string-to-int-x86-32-bit-assembler-using-nasm

_________________
Suddenly fell in love with fasm
Post 16 Sep 2020, 15:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
That is AT&T syntax, and it is the worst possible syntax.

To convert remove all % and $ symbols, reverse the order of operands. change () to [], and # to ;

That should get most of it.
Post 16 Sep 2020, 22:35
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
There is no check for something like: "-123".
Post 17 Sep 2020, 12:41
View user's profile Send private message Send e-mail 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.