12,697,620 members (28,051 online)
Rate this:
See more:
Hi,

Note: 16-bit division

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

Rate this:

## 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

This is not rocket science...:laugh:
```mov dx, 0
mov ax, 64
mov bx, 16
div bx```
AX == 4, DX == 0
v2
Zerr0cool 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

OriginalGriff 27-Jan-13 5:10am

Zerr0cool 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

OriginalGriff 27-Jan-13 6:58am

What do you expect it to do? (apart from always print "n")
Zerr0cool 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 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
Zerr0cool 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 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 27-Jan-13 7:59am

Wow...it cleared my mind a lot. Thank you:)
OriginalGriff 27-Jan-13 8:04am

You're welcome!

Top Experts
Last 24hrsThis month
 OriginalGriff 220 Asgard25 130 F-ES Sitecore 125 ppolymorphe 90 CPallini 75
 OriginalGriff 3,741 Peter Leow 2,228 Mika Wendelius 1,753 ppolymorphe 1,647 Jochen Arndt 1,454