flat assembler
Message board for the users of flat assembler.

Index > Main > Adding Commas Algo Help

Author
Thread Post new topic Reply to topic
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 01 Dec 2011, 01:02
Greetings,

If I put in a string in divisible by 3 exactly, I get no commas, others work. For example, if I put 1234567890, I get out 1,234,567,890 but if I put in 234567890 I get no commas. I've been racking my brain on this tried a couple of things, and I get weirder results. Any ideas:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; AddCommas                                                                       ;;
;;           In SI the source string, in DI destination string, in ax si's string  ;;
;;           length. On return the destination string (original DI) will have SI's ;;
;;           string with commas add.                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AddCommas:

        xor dx,dx
        mov bx,3
        div bx

.Loop:

        mov cl,[si]
        mov [di],cl
        inc si
        inc di
        cmp byte [si],0
        je .End
        dec dx
;        cmp dx,0ffffh
;        je .ResetDX
        cmp dx,0
        je .AddComma
        jmp .Loop

.AddComma:

        mov byte [di],','
        inc di

.ResetDX:

        mov dx,3
        jmp .Loop

.End:

        ret
    


I now this is one of those duh moments, but I'm tired, long day at work. Thanks!
Post 01 Dec 2011, 01:02
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Dec 2011, 02:06
Code:
AddCommas:

        xor dx,dx
        mov bx,3
        div bx 
        test dx, dx
        jz  .ResetDX    
Haven't tested this, but I think that is the problem here.
Post 01 Dec 2011, 02:06
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 01 Dec 2011, 02:11
Ye, that did it...man, there's my duh moment. Smile Thanks!
Post 01 Dec 2011, 02:11
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 16 Dec 2011, 21:03
Post 16 Dec 2011, 21:03
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1902
DOS386 17 Dec 2011, 01:56
> For completeness, here's some other links:

one more: http://freebasic.net/forum/viewtopic.php?t=12600

PS: try

Code:
        mov byte [di],','
    


->

Code:
        mov byte [di],39 ; apo "'"
    
Post 17 Dec 2011, 01:56
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 17 Dec 2011, 12:19
Image

Thanks you two, I can kind of read the ones you put in rugxulo but I am unfamiliar with those language. DOS386 the basic one is most readable. Smile Thanks to for the last line. I've been considering doing all the ASCII based characters that way, then documenting what they afterwords too.
Post 17 Dec 2011, 12:19
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.