Hello, how does division works in nasm assembly language?
I want to get the least important digits from a binary number.
ex: 1001b /10= 100.1b. The bold signed one is what i like to get.
Any suggestions?

Further explanation:
What i want to do is convert a binary number into hex.
I have a 16 bit number, and have to convert it to hex (4 digits).
1.Get each bit and convert it to decimal until it's 4 digit long. (ex: 1001=9)
2. Do <1> while the whole number is converted to dec
ex: 1010 1001 1001 1001
10 9 9 9
3.Convert dec to hex: A999

Maybe someone knows a better way of converting bin to hex? Pls do say!

Hello, how does division works in nasm assembly language?
I want to get the least important digits from a binary number.
ex: 1001b /10= 100.1b. The bold signed one is what i like to get.
Any suggestions?

Further explanation:
What i want to do is convert a binary number into hex.
I have a 16 bit number, and have to convert it to hex (4 digits).
1.Get each bit and convert it to decimal until it's 4 digit long. (ex: 1001=9)
2. Do <1> while the whole number is converted to dec
ex: 1010 1001 1001 1001
10 9 9 9
3.Convert dec to hex: A999

Maybe someone knows a better way of converting bin to hex? Pls do say!

The first part:
If all you're wanting to do is pull a specific bit out then you should look into ANDing
I believe DIV and IDIV both only store the quotient and remainder

Second part:
Converting a number to hex from decimal is pretty easy with a lookup table.
Like '0123456789ABCDEF'
Ofcourse indexing into that lookup table you realize +0 is 0 and +10 is A!
The most basic way I can think of to go from binary to decimal would be to use shifting and ANDing with a counter as to what that immediate bit represents.

I have some example code but I can't post it due external influences. I'll try to later unless someone else helps you out.

ok! That's a very good idea!
This is what i have at the moment:

section .bss
		mesage resb 2
   %macro print 2 
      mov   eax, 4
      mov   ebx, 1
      mov   ecx, %1
      mov   edx, %2
      int   80h
   %endmacro
section .data
          ascii     db        '0123456789ABCDEF'
                    db        13,10,'$'
          oct     db        98h
section .text

	global _start
_start:
                    mov       al,[oct]
                    mov       ah,al

                    and       al,0F0h
                    mov       cl,4
                    shr       al,cl
                    mov       bl,al
                    xor       bh,bh
                    mov       al,[ascii+bx]
                    mov       [mesage],al
                    and       ah,0Fh
                    mov       bl,ah
                    xor       bh,bh

                    mov       al,[ascii+bx]
                    mov       [mesage+1],al

					print mesage,9
;***EXIT***
	mov eax, 1            ; (sys_exit)
	mov ebx, 0            ; Exit with return code of 0 (no error)
	int 80h

But i get these errors at linking:
lab3b.o: In function `_start':
lab3b.asm : (.text+0x14): relocation truncated to fit: R_386_16 against `.data'
lab3b.asm : (.text+0x25): relocation truncated to fit: R_386_16 against `.data'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.