;this program does integer division
;Input byte ptr 400h = N
;      byte ptr 401h = M
;Output byte ptr 402h = N div M
;       byte ptr 403h = N mod M
;       byte ptr 404h = error code = 0 if OK = 1 if error
;
        mov     al, byte ptr 400h       ;get input
        mov     bl, byte ptr 401h
        sub     bl, 0                   ;check for div by zero
        jnz     ok
        mov     byte ptr 404h, 1        ;error - div by zero
        int     20h
ok:     mov     byte ptr 404h, 0        ;no error - set it to OK
        mov     cl, 0                   ;count for num of subtracts
lp:     sub     al, bl                  ;can we subtract?
        jc      finish                  ;I guess not.....
        add     cl, 1
        jmp     lp
finish: mov     byte ptr 402h, cl       ;cl is now N div M
        add     al, bl                  ;recreate remainder
		 mov     byte ptr 403h, al	      ;al is now N mod M
        int     20h
        end