DIVISION in assembly? (NASM)

Reply

Join Date: Jun 2008
Posts: 97
Reputation: Alex_ is an unknown quantity at this point 
Solved Threads: 2
Alex_'s Avatar
Alex_ Alex_ is offline Offline
Junior Poster in Training

DIVISION in assembly? (NASM)

 
0
  #1
May 2nd, 2009
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!
Last edited by Alex_; May 2nd, 2009 at 10:34 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 39
Reputation: sysop_fb is an unknown quantity at this point 
Solved Threads: 5
sysop_fb sysop_fb is offline Offline
Light Poster

Re: DIVISION in assembly? (NASM)

 
0
  #2
May 2nd, 2009
Originally Posted by Alex_ View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 97
Reputation: Alex_ is an unknown quantity at this point 
Solved Threads: 2
Alex_'s Avatar
Alex_ Alex_ is offline Offline
Junior Poster in Training

Re: DIVISION in assembly? (NASM)

 
0
  #3
May 2nd, 2009
ok! That's a very good idea!
This is what i have at the moment:
  1. section .bss
  2. mesage resb 2
  3. %macro print 2
  4. mov eax, 4
  5. mov ebx, 1
  6. mov ecx, %1
  7. mov edx, %2
  8. int 80h
  9. %endmacro
  10. section .data
  11. ascii db '0123456789ABCDEF'
  12. db 13,10,'$'
  13. oct db 98h
  14. section .text
  15.  
  16. global _start
  17. _start:
  18. mov al,[oct]
  19. mov ah,al
  20.  
  21. and al,0F0h
  22. mov cl,4
  23. shr al,cl
  24. mov bl,al
  25. xor bh,bh
  26. mov al,[ascii+bx]
  27. mov [mesage],al
  28. and ah,0Fh
  29. mov bl,ah
  30. xor bh,bh
  31.  
  32. mov al,[ascii+bx]
  33. mov [mesage+1],al
  34.  
  35. print mesage,9
  36. ;***EXIT***
  37. mov eax, 1 ; (sys_exit)
  38. mov ebx, 0 ; Exit with return code of 0 (no error)
  39. 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'
Last edited by Alex_; May 2nd, 2009 at 11:58 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC