Hello,
can someone help me to figure out how i can print the content stored in si ?
suppose i did:
sub si,si
inc si ---> repeated this few time.

how can i print the number in SI on the screen?

how can i print the number in SI on the screen?

You'll probably need to copy the value of SI to a variable first, but it all depends on what libraries you have (or don't) for printing numbers in the system for which you are developing.

Could you post some information about the environment/system you're using?

Could you post some information about the environment/system you're using?

i'm really new to Assembly and we just took a small assignment about it. so i'd dont know anything about libraries. all i know is that we are using TASM.
does that help?

To print any value to the screen the value is converted into
ASCII characters to be printed out on the console.
For instance the following code converts the value into the
ASCII hexadecimal representation of a value.

PrintHexW:
push ax
shr ax, 8
call PrintHexB
pop ax
push ax
and ax, 0xff
call PrintHexB
pop ax
ret
PrintHexB:
push ax
shr al, 4
call PrintHexAsc
pop ax
push ax
and al, 0xf
call PrintHexAsc
pop ax
ret
PrintHexAsc:
push ax
add al, 0x30
cmp al, 0x39
jle PrintHexAsc_e
add al, 0x7
PrintHexAsc_e:
push dx
mov dl, al
mov ah, 0x2
int 0x21
pop dx
pop ax
ret

Thx for everyone's help.
but i've came up with something that served me in my program. hope it helps others as well.
the number is stored in al .. in this example, i've stored 25 in al aqnd printed on the screen :

.model small
.stack 100H


.code
mov al,25
mov ah,0
aam
mov bx,ax
mov ah,02h
mov dl,bh
add dl,48
int 21h 
mov dl,bl
add dl,48
int 21h 

mov AH,4cH
int 21H
end

That's was a neat idea using AAM (Adjust After Multiply)
to convert a value < 100 in AL into a unpacked BCD in AX
for quickly displaying a two-digit decimal value to the console.

MOV AX, 25
AAM
ADD AX, 3030h
XCHG BX, AX
MOV DL, BH
MOV AH, 2
INT 21h
MOV DL, BL
MOV AH, 2
INT 21h

Here's a piece of code for display a 16-bit value in decimal (base 10).

putdec_val dw 0
putdec_dec_conv equ 30h
putdec_cnt dw 10000
putdec_dig db 0
putdec_digits dw 5

putdec_w:
push bp
mov bp,sp
pusha
push word [putdec_cnt]
mov ax, word [bp+4]
mov word [putdec_val], ax
mov cx, word [putdec_digits]
putdec_getdigit:
xor dx, dx
mov ax, word [putdec_val]
div word [putdec_cnt]       ;  [val] / decimal place val = quotient in AX
mov byte [putdec_dig], al   ;  Copy digits value (0..9) in the [dig] variable 
add al, putdec_dec_conv     ;  Add 30h + Digits value to get printable ASC char for digit
mov dl, al           ;  Move the digits printable ASC val into DL to be printed
mov ah, 02h          ;  move 02h into AH, AH=02h Output Char to Stdout
int 21h              ;  Print

xor dx,dx
xor ax,ax
mov al, byte [putdec_dig]   ;  Move the digits value back into AL
mov bx, word [putdec_cnt]   ;  Move the decimal place's val into BX
mul bx               ;  Multiply Decimal place's val by the digits val
                     ;  Ex. 9 (Digits val) * 100 (dec. place's val.)  = 900
                     ;  Ex. 9 (Digits val) * 10  (dec. place's val.)  = 90

sub word [putdec_val], ax   ;  Subtract the current value from the value of the
                     ;  current digit, for ex. if the current digit
                     ;  is 9 and the cur. decimal place is 10
                     ;  the and the cur. val 93 it would be 93 - 90 = 3
xor dx, dx
mov ax, word [putdec_cnt]
mov bx, 10
div bx               ; if decimal place is 100, the 100 / 10 = 10 next lower
                     ; decimal place, result is returned in AX.

mov word [putdec_cnt], ax   ; Place value of the next lower decimal place ,
                     ; in the [cnt] var.
dec cx
jz putdec_exit
jmp putdec_getdigit
putdec_exit:
pop word [putdec_cnt]
popa
pop bp
ret
This article has been dead for over six months. Start a new discussion instead.