I cant seem to get the right remainder output, then whenever i try to divide by sign numbers everything goes hay wire, i have written functions for input and output, they work fine so i know that isnt the problem, my inputs are for A and B, i am trying to solve for Ax+b<=0, thanks for any help on this matter; here is my code
.MODEL SMALL
.STACK 100H
.DATA
chr_prompt DB 'Please input a number:',0
newprompt DB 'Please input another number',0
spr DB'Resolving Ax+B>=0',0
resa DB'Input A:',0
resb DB'Input B:',0
again DB 'Would you like to continue:',0
.CODE
INCLUDE io.mac
main PROC
.STARTUP
read_char:
PutStr chr_prompt
GETINT ax
nwln
PutStr newprompt
GETINT cx
nwln
PutStr spr
PutInt ax
nwln
PutStr resa
PutInt ax
nwln
PutStr resb
putint cx
nwln
; this is where the division occurs, I only need to use
;-127 to 127
sub dx,dx
cbw
idiv cx
PUTint ax
putch '.'
putint dx
nwln
PutStr again
getch al
cmp al,'y'
je read_char
cmp al,'n'
je done
nwln
done:
.EXIT

main ENDP
END main
Posted on 2001-11-18 16:27:56 by jps
I havent tested it but think you should use "cwd" instead of "cbw"
Posted on 2001-11-19 02:33:43 by japheth
Do you preserve the values of the register in your GET*** and PUT*** functions? After calling a function, you may have different values in your ax & cx registers.

As you are solving -B/A, you need (when dividing) -B in ax, and A in SRC.
So you seem to have A and B the wrong way around!
You also do not negate B at any time.

Try the following code:


mov al, 5 ; Force B to check the algo
mov cl, 1 ; Force A to check the algo

neg al
cbw
idiv cl

push ax ; Store ax in case PUTint corrupts it!

;If you can only PUTint 16bit data do this:
;cbw

PUTint al
putch '.'

pop ax ; Restore ax so we can get the remainder

;If you can only PUTint 16bit data do this:
;shr ax, 16
;cbw

putint ah
nwln


Hardwireing data will help you rule out whether or not you've got the right algo, and so eliminate it or identify it as your problem.

Mirno
Posted on 2001-11-19 09:51:35 by Mirno