T
T
timur1022018-10-30 23:25:03
assembler
timur102, 2018-10-30 23:25:03

What is the line add dl,'0' for?

org 100h

; складываем два числа
mov ax,5 
add ax,10
xor cx,cx
mov bx,10
; переводим число в "строку"
lp1:
  xor dx,dx ; обнуляем dx
  div bx    ; делим ax:bx
  add dl,'0' ; зачем эта строчка нужна? ЗАЧЕЕЕЕЕЕМ? 
  push dx   ; кладём в стек остаток от деления 
  inc cx
  or ax,ax  
  jnz lp1   

lp2:
  pop ax
  int 29h
  loop lp2
  mov ah,4ch
  int 21h

I don't understand this line: add dl,'0'
What does it do? Why is she needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-10-30
@timur102

Well, somehow it happened, purely by chance, that the numeric characters '0'-'9' in the ASCII table are in the same order as the numbers 0-9 in the decimal number system.
So, if we take the character '0' and add a number from 0 to 9 to its code, then, oddly enough, we get the code of the character corresponding to this number.
'0' + 0 = '0'
'0' + 1 = '1'
etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question