Skip to content

Instantly share code, notes, and snippets.

@nathanpc
Created June 18, 2011 15:57
Show Gist options
  • Save nathanpc/1033216 to your computer and use it in GitHub Desktop.
Save nathanpc/1033216 to your computer and use it in GitHub Desktop.
Dividing By Negative Numbers
; ********************
; * DIVIDE.ASM *
; ********************
.model small
.stack 512d
.data
a dw -9d
b db 2d
x db 0, '$'
.code
mov ax, @data
mov ds, ax
mov ax, a
mov bl, b
idiv bl
mov x, al
sub bx, bx
mov bl, x
mov ah, 02h
mov dl, bl
mov cl, 04h
shr dl, cl
add dl, 030h
cmp dl, 039h
jle value1
add dl, 07h
value1:
int 021h
mov dl, bl
and dl, 0Fh
add dl, 030h
cmp dl, 039h
jle value2
add dl, 07h
value2:
int 021h
mov ah, 04Ch
int 021h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment