title: Macro printing a value stored in a byte. Assembly masm
body: <p>Assembly, masm </p>
  
  <p>Hey, I wrote macro which prints the 1 byte value stored in dane1 segment.</p>
  
  <p>I divide the value by 16, then i push reminder to stack until value==0. Then I pop reminders convert them to ASCII code, and print them.</p>
  
  <p>Shall someone look at my code? What should I change to make it simpler?</p>
  
  <p>I don't want to do each time:</p>
  
  <pre><code>mov dl,67h
  mov ds:[v1],dl
  print v1
  </code></pre>
  
  <p>Is it possible to modify this macro, so that it could use it:</p>
  
  <pre><code>print 67h
  print al
  </code></pre>
  
  <p>Thanks for any help.</p>
  
  <pre><code>assume  cs:code1
  .186
  
  dane1   segment
  v1 dw 0D9h    ;to use macro
  dane1   ends
  
  print macro value
      pusha
      mov ax,seg value
      mov ds,ax
      mov ax,ds:[value]
      xor cx,cx        ;CX - repetitions
      analyse:         ;pushes the digits into stack
          mov dl,16    ;divisor
          div dl                 ;divide number in AX by 16   
          xor dx,dx
          mov  dl,ah ;remainder into the stack   
          push dx 
          xor ah,ah ;        prepare quotient for next loop       
          inc cx               ;increase repetitions    
          cmp ax,0             ;break condition
          jne analyse    
      begin1:                 ;print character stored in the stack
          pop dx              ;pop to DL
          cmp dl,10d          ;is DL digit or char
          jb digit                         
              char:            ;convert to ASCII 
                  add dl,55
                  jmp begin2  
              digit:
                  add dl,'0'
                  jmp begin2  
           begin2:
           mov ah,2           ;print character converted to ASCII 
           int 21h
           loop begin1
      popa
  endm 
  
  code1   segment
  
  start1: mov ax,seg top1
      mov ss,ax
      mov sp,offset top1 
  
      print v1
  
  mov ah,4ch
  int 21h
  
  code1   ends
  
  
  
  stos1   segment stack
      dw  200 dup(?)
  top1    dw  ?
  stos1   ends
  
  end start1      
  </code></pre>