Simpler way of doing this?

Is their a simpler way of converting an integer to hex in assembly language.
This is what I know works, but I want to know is there an easier/simpler way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Stack frame
    .equ anInt,-4
    .equ localSize,-16
# Read only data
    .section .rodata
prompt:
    .string "Enter an integer number: "
scanFormat:
    .string "%i"
printFormat:
    .string "%i = %x\n"
# Code
    .text # switch to text segment
    .globl main
    .type main, @function
main:
 pushq  %rbp                # save caller’s base pointer
 movq   %rsp, %rbp          # establish our base pointer
 addq   $localSize, %rsp    # for local variable

 movl   $prompt, %edi       # address of prompt text string
 movl   $0, %eax            # no floating point args.
 call   printf              # invoke printf function

 leaq   anInt(%rbp), %rsi   # place to store integer
 movl   $scanFormat, %edi   # address of scanf format string
 movl   $0, %eax            # no floating point args.
 call   scanf               # invoke scanf function

 movl   anInt(%rbp), %edx   # the integer
 movl   anInt(%rbp), %esi   # two copies
 movl   $printFormat, %edi  # address of printf text string
 movl   $0, %eax            # no floating point args.
 call   printf              # invoke printf function

 movl   $0, %eax            # return 0
 movq   %rbp, %rsp          # delete local variables
 popq   %rbp                # restore caller’s base pointer
 ret                        # back to calling function 


Here is the output. So I know this works.

Enter an integer number: 125
125 = 7d
I have never done assembly before so it looks foreign but maybe this works?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Begin:
    Mov A,#99h
    Acall Con_Dec_2_Hex
    Sjmp $
 
Con_Dec_2_Hex:
    Push Acc
    Anl A,#F0h
    Swap A
    Mov B,#0Ah
    Mul AB
    Xch A,B
    Pop Acc
    Anl A,#0Fh
    Add A,B
    Ret


I found it here:
http://www.edaboard.com/thread248460.html
yeah no that did not work.
Topic archived. No new replies allowed.