Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Could you please help me in performing the division operation in nasm.

Note: 16-bit division

Regards,
Kiran
Posted

1 solution

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:
ASM
mov dx, 0
mov ax, 64
mov bx, 16
div bx
AX == 4, DX == 0
 
Share this answer
 
v2
Comments
[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

please...
OriginalGriff 27-Jan-13 5:10am    
Answer updated
[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

require your guidence please :)
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'

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900