Click here to Skip to main content
11,478,174 members (70,292 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASM
Hi,
Could you please help me in performing the division operation in nasm.

Note: 16-bit division

Regards,
Kiran
Posted 26-Jan-13 23:19pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Dpbends on what you are trying to do: use the NASM division and modulus operators (which only work on constants at assembly time) or the actual microprocessor to work on variable values at run time.

If the former, see here: http://cs.nyu.edu/courses/fall02/V22.0201-001/nasm_doc_html/nasmdoc3.html#section-3.5.6[^]

If the latter, see here: http://cs.nyu.edu/courses/fall02/V22.0201-001/nasm_doc_html/nasmdocb.html#section-B.4.59[^]

"yes...i have referred to the manuals but still had problems in figuring out the operation.
Could you please help me with an example probably with the below values in terms of nasm 16-bit?

64/16
remainder=0
quotient=4

please..."


This is not rocket science...Laugh | :laugh:
mov dx, 0
mov ax, 64
mov bx, 16
div bx
AX == 4, DX == 0
  Permalink  
v2
Comments
Zerr0cool at 27-Jan-13 4:44am
   
yes...i have referred to the manuals but still had problems in figuring out the operation.
Could you please help me with an example probably with the below values in terms of nasm 16-bit?

64/16
remainder=0
quotient=4

please...
OriginalGriff at 27-Jan-13 5:10am
   
Answer updated
Zerr0cool at 27-Jan-13 6:30am
   
Well I really thank you...but something is going wrong in my program to print the reminder. Could you please help.
Below is the sample code I am working on


; source no: 1040
; divide source by 16
; quotient is 65
; remainder is 0
; problem: but remainder is not correctly validated. Am i wrong somewhere
bits 16
org 0x7c00

start:
jmp demo

demo:
xor dx, dx
mov ax, 0x0410 ; 1040
mov bx, 0x0010 ; 16
div bx

mov ah, 0x000e
int 0x10

mov ax, dx
cmp al, 0x0030
je yes
mov al, 'n'
mov ah, 0x000e
int 0x10
jmp $
yes:
mov al, 'y'
mov ah, 0x000e
int 0x10


times 510-($-$$) db 0x0000
dw 0xaa55

require your guidence please :)
OriginalGriff at 27-Jan-13 6:58am
   
What do you expect it to do? (apart from always print "n")
Zerr0cool at 27-Jan-13 7:04am
   
0's equivalent hexadecimal is 0x30. so in this case it should print 'y' instead of 'n'. I am confused as to why it prints 'n'
OriginalGriff at 27-Jan-13 7:20am
   
When you divide 0x410 by 0x10, you get a quotient of 0x41 in AX and a remainder of 0x0 in DX
You move the valuer in DX to AX, and compare the low byte against 0x30. Since the remainder when divided by 16 will always be in the range 0-15 it will never, ever match 48 (0x30)
Perhaps if you compared with zero? Or
OR Al,AL
instead?
Zerr0cool at 27-Jan-13 7:32am
   
but according to ascii table the character equivalent of 48(decimal), 0x30(hexadecimal) is 0. but 0x00 is not character equivalent 0 right?
OriginalGriff at 27-Jan-13 7:56am
   
ASCII is not the same a Binary. An ASCII '0' is 0x30 in binary, an binary 0x0 is an ASCII NULL
The Ascii characters are the ones you find in strings and char arrays - binary values that you can divide are different!
Zerr0cool at 27-Jan-13 7:59am
   
Wow...it cleared my mind a lot. Thank you:)
OriginalGriff at 27-Jan-13 8:04am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 184
1 OriginalGriff 160
2 Frankie-C 160
3 Sascha Lefèvre 145
4 F-ES Sitecore 120
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,256
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100