15,664,272 members
See more:
Hi,

Note: 16-bit division

Regards,
Kiran
Posted

## 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:
ASM
```mov dx, 0
mov ax, 64
mov bx, 16
div bx```
AX == 4, DX == 0

v2
[no name] 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
[no name] 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")
[no name] 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'