flat assembler
Message board for the users of flat assembler.

Index > Main > Loading a moving offset into a reg

Author
Thread Post new topic Reply to topic
moveax41h



Joined: 18 Feb 2018
Posts: 59
moveax41h 16 Mar 2018, 08:58
In the following code I am trying to check each char in a char array one at a time:

Code:
encode:
mov al, offset [bInput+ecx] ; Put the char* to first element into eax
cmp byte [eax], 32 ; check for space
je endme
cmp byte [eax], 97
jl not_lower_case
cmp byte [eax], 122
jg not_lower_case   
    

There is code below this which does a comparison and then increments ecx before looping back up to the encode label.

However, something is wrong with my syntax and this first caused a segfault, now it won't even assemble. Is there a way to properly do this or do I need to use esi or edi? Thanks.

_________________
-moveax41h
Post 16 Mar 2018, 08:58
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 16 Mar 2018, 09:46
[eax] is already a "char" by the second line. No longer a valid address.

What you need is a proper index addressing setup before going through the bytes.

But you could instead use "cmp al,32". Makes more sense.
Post 16 Mar 2018, 09:46
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: 20519
Location: In your JS exploiting you and your system
revolution 16 Mar 2018, 11:07
Use the value in al directly. Also fasm supports ASCII characters natively, no need to convert to raw magic numbers. Plus use unsigned checks for unsigned values (jb and ja)
Code:
encode:
        mov     al, [bInput+ecx]        ; Put the char* to first element into al
        cmp     al, ' '
        je      endme
        cmp     al, 'a'
        jb      not_lower_case
        cmp     al, 'z'
        ja      not_lower_case    
Post 16 Mar 2018, 11:07
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 16 Mar 2018, 19:53
Also no need to use the offset keyword. It is just a useless junk invented by TASM/MASM (?) developers.
Post 16 Mar 2018, 19:53
View user's profile Send private message Visit poster's website Reply with quote
moveax41h



Joined: 18 Feb 2018
Posts: 59
moveax41h 17 Mar 2018, 22:31
Thank you, this was very helpful advice!

_________________
-moveax41h
Post 17 Mar 2018, 22:31
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.