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.
divinstruction for that, and certainly not by10. Each group of 4 bits is represented by one hex digit, so you can just read groups of 4 input bits and look up the appropriate ASCII hex digit. Like a simpler version of How to convert a binary integer number to a hex string?