flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > displaying hex-values

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
Ali.A



Joined: 08 Jan 2018
Posts: 130
damn, i feel like im a dummmmmm.

you are smart, honestly i couldnt think this way:

lods ; loads single byte from esi to al
...
sub al,'0' ; which is 30hex (ascii 30 = 0 || 39 = 9)
cmp ... ; if result is less than Ah (10d)
then store it (first shift of ebx is not counted because bl is 0)
EDIT: forgot to mention that shl x,4 will shift 4 bits which means a nibble
where you can store 0x0F in 1 nibble (4bits)
otherwise subtract 7 ; because:

ascii numbers starts from 30 to 39 hex (0-9)
and ascii chars start from 41, the distance between 39h and 41h is 7
...
loop back til al is 0 (null terminated string)


wow, you are genius .. (im bad in math sorry)
whats great in this, it doesnt matter if its a or A, f or F.

Q. is it important to clear DF?
anyhow bunch of thanks man.


Last edited by Ali.A on 30 Jun 2018, 16:30; edited 1 time in total
Post 30 Jun 2018, 11:46
View user's profile Send private message Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 130
ok seems to be important to clear DF
"When the DF flag is set to 0, string operations increment the index registers" esi/edi

:: BUT when i debugged my flag using olly, it shows the DF was already '0'
maybe i can get rid of cld?
Post 30 Jun 2018, 15:57
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 444
Location: Belarus
Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.
Post 30 Jun 2018, 22:51
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16106
Location: Squiddler's Patch
Ali.A wrote:
ok seems to be important to clear DF
"When the DF flag is set to 0, string operations increment the index registers" esi/edi

:: BUT when i debugged my flag using olly, it shows the DF was already '0'
maybe i can get rid of cld?
This is dependant on the OS. Many OSes will start applications with DF=0. Windows does this. But if you want to run your code in a different context then it might not be guaranteed that DF is in any particular state.
Post 30 Jun 2018, 22:55
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 130
meant debugged my program* lol

anyhow, thanks for the info rev.
Post 01 Jul 2018, 09:42
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1255
Location: In a West End town
Ali.A wrote:
damn, i feel like im a dummmmmm.

you are smart, honestly i couldnt think this way:

lods ; loads single byte from esi to al
...
sub al,'0' ; which is 30hex (ascii 30 = 0 || 39 = 9)
cmp ... ; if result is less than Ah (10d)
then store it (first shift of ebx is not counted because bl is 0)
EDIT: forgot to mention that shl x,4 will shift 4 bits which means a nibble
where you can store 0x0F in 1 nibble (4bits)
otherwise subtract 7 ; because:

ascii numbers starts from 30 to 39 hex (0-9)
and ascii chars start from 41, the distance between 39h and 41h is 7
...
loop back til al is 0 (null terminated string)

wow, you are genius .. (im bad in math sorry)
whats great in this, it doesnt matter if its a or A, f or F.


Nice job Ali.A.
lodsb also advances the esi pointer, that's why you don't have to add an extra: add esi,1.

Quote:

Q. is it important to clear DF?
anyhow bunch of thanks man.

revolution gave the answer for this.
I guess i gained some good habits from the forum. Smile
Post 02 Jul 2018, 08:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< 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-2018, Tomasz Grysztar.

Powered by rwasa.