flat assembler
Message board for the users of flat assembler.

Index > MenuetOS > subroutine int2asc

Author
Thread Post new topic Reply to topic
C.H.R



Joined: 28 Jul 2017
Posts: 5
Location: Colombia
C.H.R 20 Dec 2017, 22:00
Thank you very much Ville
Im sorry, I dont understood the part of ( until that no left part integer in rax)

I wrote the following:

Code:
int2asc:    ; function to convert int to ascii
    push    rbp  ; args in: integer(RDI), ptr buffer(RSI)
    mov rbp, rsp
    sub rbp, 0x10
    
    xor rax, rax
    xchg rdi, rsi
    
    mov rcx, 0
    mov r15, 10
    mov rax, rsi
  np:
    div r15
    add dl, 48
    mov byte[rdi], dl
    inc rdi
    dec rax
    cmp rax, 0
    jnz np
    
    leave
    ret
    


Say me what's wrong here.

Much obliged.
Nice day.
Post 20 Dec 2017, 22:00
View user's profile Send private message Send e-mail Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 21 Dec 2017, 11:51
Code:
int2asc:    ; function to convert int to ascii ; args in: integer(RDI), ptr buffer(RSI)
        xchg    rdi,rsi
        mov     rax,rsi
        mov     r15d,10
np:
        xor     edx,edx
        div     r15
        add     dl,48
        mov     [rdi],dl
        inc     rdi

        or      rax,rax
        jnz     np
        ret
    

stack frame and "dec rax" is unnecessary

_________________
smaller is better
Post 21 Dec 2017, 11:51
View user's profile Send private message Reply with quote
C.H.R



Joined: 28 Jul 2017
Posts: 5
Location: Colombia
C.H.R 21 Dec 2017, 21:56
Thanks CandyMan. I will test it inmediatly. Thanks for the push.
Post 21 Dec 2017, 21:56
View user's profile Send private message Send e-mail Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 22 Dec 2017, 06:12
It looks like CandyMan reads the digits backwards or has quite a unique system.

Code:
PrintUnsignedInteger:
        ; in: rax unsigned integer
        ; io: rdi string
                mov   ecx, 10
                mov   r8, rsp
        .l1:    xor   edx, edx
                div   rcx
               push   rdx
               test   rax, rax
                jnz   .l1
        .l2:    pop   rax
                add   al, '0'
              stosb
                cmp   rsp, r8
                 jb   .l2
                ret    
Post 22 Dec 2017, 06:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20304
Location: In your JS exploiting you and your system
revolution 22 Dec 2017, 08:41
tthsqe wrote:
It looks like CandyMan reads the digits backwards or has quite a unique system.
It's called little endian. Most spoken and written natural languages use big endian base-10, but I wonder if that is really the best choice?
Post 22 Dec 2017, 08:41
View user's profile Send private message Visit poster's website 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 can 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.