Convert binary to hexadecimal using MASM32

20 Views Asked by At

This is my MASM32 code:

include\masm32\include\masm32rt.inc
.data
    n dd 0
.code

convertBH proc num:dword, output:dword
    local temp:dword
    local index:dword
    local hex:dword
    local remainder:dword
    mov index, 1
    mov hex, 0
    
  laplai:
    mov edx, 0
    mov eax, num
    mov ebx, 10
    div ebx
    mov remainder, edx

    mov eax, remainder
    mul index
    lea eax, [eax + hex]
    mov hex, eax
    
    mov eax, index
    mov ebx, 2
    mul ebx
    mov index, eax

    mov eax, num
    mov ebx, 10
    div ebx
    mov num, eax
    cmp num, 0
    jne laplai
    je ketthuc
            
  ketthuc:
    print str$(hex)
    ret
convertBH endp

start:
    mov n, sval(input("Moi ban nhap so n: "))
    invoke convertBH,n
    exit
end start

If there is other code than mine, please give it to me, I'm writing in masm32.

0

There are 0 best solutions below