Hi everybody!

Here comes two procedures to print signed and unsigned integers to the screen.... It can also print numbers in other bases given by the base register (bx). The number to print is given by the accumulator (ax)...

org 100h
mov ax,-1253 ; Number: -1253
call putsint ; Print it! (signed integer; base: 10 (default))
call newline
mov ax,4C8Fh ; Number: 4C8Fh (hex value)
mov bx,16 ; Base: 16 (hexadecimal)
call putint ; Print it! (unsigned integer)
call newline
mov ax,4360 ; Number: 4360
mov bx,10 ; Base: 10 (decimal)
call putint ; Print it! (unsigned integer)
xor ax,ax ; Function: Wait for key...
int 16h
mov ax,4C00h ; Exit to DOS
int 21h
; Procedures
; Go to next line
newline:
push ax dx
mov ah,02h
mov dl,0Dh
int 21h ; Output CR to screen
mov dl,0Ah
int 21h ; Output LF to screen
pop dx ax
ret
; Print a signed integer to screen
; bx = base (default = 10), ax = number
putsint:
push ax dx
cmp bx,0
jne .start ; if bx <> 0 then ...let's go!
mov bx,10 ; else bx = 10
.start:
cmp bx,10
jne .printit ; if it's not a decimal integer, we don't print any signs
cmp ax,0
jns .printit ; if it's not negative, we don't print any signs either
push ax
mov ah,02h
mov dl,"-"
int 21h ; output the "-"
pop ax
neg ax ; do the number positive
.printit:
call putint ; now we can print the number...
pop dx ax
ret
; Print an unsigned integer to screen
; bx = base (default = 10), ax = number
putint:
push ax bx cx dx
cmp bx,0
jne .start ; the same as in putsint... (if bx = 0 then bx = 10)
mov bx,10
.start:
xor cx,cx ; cx = 0
.new:
xor dx,dx ; dx = 0
div bx ; number / base
push dx ; push the remainder
inc cx ; increase the "digit-count"
cmp ax,0 ; if the quotient still is not 0, do it once more
jnz .new
.loop:
pop dx ; pop the remainder
add dl,30h ; convert the number to a character
cmp dl,"9"
jng .ok ; if the charater is greater than "9" then we have
add dl,7 ; to add 7 to get A as 10, B as 11, and so on...
.ok:
mov ah,02h ; output the character
int 21h
loop .loop
pop dx cx bx ax
ret

Enjoy!!!

Regards,

Tommy