Hi all:
I wrote the following simple program to test printdec proc (which was given by my professor). However, i am getting some unwanted characters after printing 20 (label val).
Do you guys know why i am getting those characters.
Thank you very much in advance.
Ron
%title "test program"
.model small
.stack 256
.data
info DB 13,10,9
info1 DB 'my test program',13,10,10,'$'
val DW 20
.code
mymain:
mov AX, @data
mov DS, AX
mov ah,9
mov DX,offset info
int 21h
mov AX, val
call printdec
mov ah,4ch
int 21h
%title "printdec"
.model small
.data
;;;charbuf db 6 dup(''),'',10,13
charbuf db 6 dup(''),13,10,'$'
.code
PUBLIC printdec
printdec proc
;*************************************************************************************
;print 16-bit numbers, whether positive or negative,on the screen *
;with minus signs directly in front of negative number *
;input: numbers to print is passed in ax register *
;no registers are destroyed *
;*************************************************************************************
pushf ;save all registers
push ax
push bx
push cx
push dx
push bp
push di
mov bx,offset charbuf ;address of buffer area
mov cx,3
sub di,di
up: mov [word ptr bx+di],02020h ;blank the buffers between calls
add di,2
loop up
sub ch,ch
mov di,5 ;end of buffer area
cmp ax,0
jge go ;skip if positive or zero
mov ch,02dh ;minus sign
neg ax ;make positive
go: mov bp,10
top: sub dx,dx ;clear to prepare for division
;;; idiv bp ;divide-- get remainder in dx, quotient in ax
div bp ;divide-- get remainder in dx, quotient in ax
add dl,30h ;transfer data to write to screen
mov [bx+di],dl
dec di ;move backwards through buffer
cmp ax,0 ;are we done?
jne top ;if not do it again
mov byte ptr[bx+di],ch ;move minus sign
mov dx,bx
mov ah,09h ;dos output character to screen
int 21h
pop di ;restore register
pop bp
pop dx
pop cx
pop bx
pop ax
popf
ret
printdec endp
end mymain