Thursday, February 26, 2015

Constructing Binary Tree from In-Order and Pre-Order traversals - C++

/*
Binary Search Tree Implementation in C++
*/
#include<iostream>

using namespace std;

struct node{
char data;

node * left;
node * right;
} *root;


void printTree(node  * root){
if(root){
cout<<"(";
printTree(root->left);
cout<<root->data<<",";
printTree(root->right);
cout<<")";
}
}

int search(char A[], char key, int start, int end){
int pos = -1;
for(int i=start; i<= end; i++){
if(A[i] == key){
pos = i;
break;
}
}

return pos;
}

int preIndex = 0;
node * makeTree(char inOrder[], char preOrder[], int start, int end){
if(start > end){
return NULL;
}
node * temp = new node;
char key = preOrder[preIndex];
temp->data = key;
preIndex++;

if(start == end){
return temp;
}

int inIndex = search(inOrder, key, start, end);
if(inIndex == -1)
{
cout<<"Mismatch in preOrder and inOrder lists";
return NULL;
}

temp->left = makeTree(inOrder, preOrder, start, inIndex-1);
temp->right = makeTree(inOrder, preOrder, inIndex+1, end);
return temp;
}

int main(){
int n = 6;

char inOrder[] = {'D', 'B', 'E', 'A', 'F', 'C'};
char preOrder[] = {'A', 'B', 'D', 'E', 'C', 'F'};

root = makeTree(inOrder,preOrder,0,n-1);
printTree(root);

return 0;
}

Wednesday, February 25, 2015

Binary Search Tree implementation in C++

/*
Binary Search Tree Implementation in C++
*/
#include<iostream>

using namespace std;

struct node{
int data;

node * left;
node * right;
} *root;


node * insert(node *root, int e){
if(root == NULL){
root = new node;
root->data = e;
return root;
} else if ((root->data) > e) {
root->left = insert(root->left,e);
} else if ((root->data) < e) {
root->right = insert(root->right,e);
}

return root;

}

node * search(node * root, int e){
if(root == NULL){
return NULL;
} else if(root->data == e){
return root;
} else if(root->data > e){
return search(root->left,e);
} else {
return search(root->right,e);
}
}

void makeTreeFromArray(int A[], int n){
for(int i=0; i<n;i++){
root = insert(root, A[i]);
}
}

void printTree(node  * root){
if(root){
//cout<<"(";
printTree(root->left);
cout<<root->data<<"  ";
printTree(root->right);
//cout<<")";
}
}

int countLeaves(node * root){
if(root == NULL){
return 0;
} else {
if( (root->left == NULL) && (root->right == NULL) ){
return 1;
} else {
return countLeaves(root->left) + countLeaves(root->right);
}
}
}
node * findMax(node * root){
if(root == NULL){
return NULL;
} else if(root->right == NULL){
return root;
} else {
return findMax(root->right);
}
}

node * deleteNode(node * root, int e){
if(root == NULL){
cout<<"Element not found";
} else if(e > root->data){
root->right = deleteNode(root->right, e);
} else if(e < root->data){
root->left = deleteNode(root->left, e);
} else {
if(root->left && root->right){
node * temp = findMax(root->left);
root->data = temp->data;
root->left = deleteNode(root->left, temp->data);
} else {
node * temp = root;
if(root->left){
root = root->left;
}else if(root->right){
root = root-> right;
} else {
root = NULL;
}
delete temp;
}
}
return root;
}



int main(){
int A[] = {6,2,10,1,3,8,11,7,9,5,4};
int n = 11;

makeTreeFromArray(A,n);
printTree(root);

cout<<"\n";

root = deleteNode(root, 6);
printTree(root);
cout<<"\nNumber of leaves : "<<countLeaves(root)<<"\n";
return 0;
}

KMP String Matching in C++


/*
 Program to match a pattern in a given string using KMP Algorithm
 Run time of the Algo : O(n + m)
  n - Size of String
  m - Size of Pattern
 @author - yazar : yazar.y@gmail.com
*/
#include <iostream>
#include<cstring>

using namespace std;

//Variable to strore the prefix function
//If there is a mismatch between T[i] and P[j] then we will look into 
//F[j-1] to get the next potential match location
int F[200];

//Function to compute Prefix function for the given pattern
void createPrefixTable(char P[], int m){
 int i = 1;
 int j = 0;
 //If there is a mismatch in the 0th location of pattern, 
 //it is then good to look again at 0th position for a match
 F[0] = 0;
 
 //Loop to set each field of prefix table
 while(i<m){
  //If ith location in prefix table matches that of jth location
  //then set the next location to be matched in case of failure as 
  //j+1
  if(P[i] == P[j]){
   F[i] = j+1;
   i++;
   j++;
  } else if(j>0){
   //If there is a mismatch while computing the 
   //match prefix with the pattern,
   // Set the value of j to next potential point of match
   j = F[j-1];
  } else {
   F[i] = 0;
   i++;
  }
 
 }
}

//Function to match a pattern within a text
int matchPattern(char T[], int n, char P[], int m){
 //Computing prefix table for matching
 createPrefixTable(P,m);
 int i=0, j=0;
 
 //Loop to iterate throughout the text
 while(i<n){
  //If there is a match in the current character within the pattern
  if(T[i] == P[j]){
   //If the entire pattern is matched, return current location
   if(j == (m-1) ){
    return i - j;
   } else {
    //Otherwise increment i and j, so that 
    //consecutive Pattern positions will be matched
    i++;
    j++;
   }
  } else if(j > 0){
   //If there is a mismatch, set the value 
   //of j to next potential point of Match
   //(ie. F[j-1] as there is a match till P[j-1])
   j = F[j-1];
  } else {
   i++;
  }
 }
 
 return -1;
} 

int main(){
 char P[200], T[500];
 
 //Readin the Text and pattern from user
 cout<<"Enter a pattern : ";
 cin>>P;
 
 cout<<"Enter a String : ";
 cin>>T;
 int n, m;
 
 n = strlen(T);
 m = strlen(P);
 
 //Calling the function to perform match
 int location = matchPattern(T,n,P,m);
 
 if(location == -1){
  cout<<"Pattern "<<P<<" Not found in String "<<T<<"\n";
 } else {
  cout<<"Pattern "<<P<<" found in the string "<<T<<" at "<<location<<"\n";
 }
 return(0);
}

Monday, March 10, 2014

Quick Reference on Data Structures And Algorithms

This is a quick reference material on Data Structures & Algorithms. We have made it as an hand-out for a placement oriented session on Data Structures And Algorithms:

https://www.dropbox.com/s/jbtbk718fs7rcjn/dsa.pdf


Sunday, February 10, 2013

Saturday, February 9, 2013

Basic Linux Commands


Basic BASH Commands:

ls: Displays the content of a directory
If no external option is given, it will display the contents of present working directory.

Eg: ls ./abc
ls
ls ~/user
- a : Option to print all files(including hidden files)
- l : Option to give a long of file details.
Eg: ls -a
ls -al
ls -l /

NB: ~ : Denotes the home directory of current user
/ : Denotes the root directory of the Linux System.

Eg: ls /
ls -a ~/

pwd: Prints the current(present) working directory.

cd <directory> : Changes the working directory to the directory specified.
Eg: cd ~
cd /
NB: cd .. will make the terminal to move to the parent directory of present working directory.
cd . Will make the terminal to move to the current directory itself.

passwd : Changes the password of current user account.

touch <filename> : Creates a new file
Eg: touch abc.txt
touch ~/abc.txt

nano : A simple text editor

cp <file_src> <file_dest> : Copies a source file to a destination directory with or without renaming (File will be renamed if file_dest is not a directory).
-r or -R or –recursive : Recursive copy or copy all the subdirectories as well.
Eg: cp ./abc.txt ./dir2/efg.txt
cp -r ./abc ./dir2

mkdir <dir_name> : Creates a new directory.
-p, --parents : Creates intervening parent directories if they do not exist.

mv <source> <dest> : Cut and paste source file to the destination and rename if dest is not a directory. mv is used also for renaming a file.
Eg: mv ./abc/sample.txt ./efg
mv ./efg/sample.txt ./efg/sample2.txt

rmdir <dir_name> : Deletes an empty directory.

rm <file_name>: Removes a file.
-r option can be used to remove directories as well recursively.
-i option can be used to warn before deleting.


command --help : Displays a simple help page for a command.

man <command> : To get the manual page for a command. Press 'q' to exit.

info <command> : To get the info page for a command.

whatis <command> : gives a short description about the command.
Eg: whatis ls

apropos <keyword> : search the manual page names and descriptions for commands
Eg: apropos editor

time : Displays the current system time.

cal : Displays the calender for the current month.
Eg: cal #Calender for the current month
cal 2 2013 #Calender for February 2103
cal 2012 #Calender for the year 2012

ps : Displays the processes created by the current user.

who : Displays all the users currently logged into the system.

w : Displays all the users currently logged into the system and their resours utilization.

cat : Display the content of a file on to the screen.

wc : Word Count – Counts the number of lines, words and characters in a text file.
Eg: wc sample.txt

which <command> : Displays the actual location of the command / application.

exit or logout : Terminates the current session.

Redirecting output of a command to file:
Eg: ls -al > new.txt

Typing two or more commands in a single line:
Eg: ls -al ; mkdir abc

Comments given after commands:
Eg: ls -al #Long listing of pwd contents.

echo “<TEXT>” : Prints a text into console.
Eg: echo “Hello World”

su : Used to change user account, either to super user or any other user account.

NB: In Ubuntu based linux systems, we use sudo (SUper User DO) to exicute a command with root privilage.
Eg: sudo mkdir /abc
sudo apt-get update

script
---------------------------
--------------------------- : Records the BASH Session to the file typescript
---------------------------
exit


sort <filename> : Sorts a text file

uname -a : Prints the information about the linux installed in the system.

lsb_release -a : Prints the version information about the linux installed.


Keyboard Shortcuts:
Key Combination
Use
Ctrl + D
Same as exit , exits or terminates current session
Ctrl + C
Closes the currently running program in foreground
Ctrl + Z
Suspends the currently running program
Ctrl + H
Same as backspace
Ctrl + L
Clears the terminal
Same as clear command
TAB
Predicts and completes a command
TAB TAB
Lists all command completion possibilities.



Files & Directories in Linux Systems:
  • In Linux all the things excepts processes are generally considered as files(devices, directories, etc).
  • Directories can be treated as special file that contains the list of files contained in it.
  • In the tree structure for directory all the directories contains two pointers . and .. which points to the current directory and parent directory respectively.
  • All the files also have an inode number which along with . And .. pointers identifies a file in the directory tree structure. Give -i option along ith ls to get the inode number as well.
  • Hidden files have names preceding with a '.'


Important Directiories in / (Root Directory):

bin : Common files shared by system, administrator and users.(Eg: commands)
boot : vmlinuz(Kernel Files), GRUB
dev : References to hardware peripherals.
etc : Configuration files(Similar to the control panel in windows)
home : Directories and home folders for users.
initrd : Information needed during booting.
lib : Library Files
lost + found : Files saved during failures.
var :Variable files like log details, server pages, temporary variables etc.
usr : Programs, libraries, documentation for all user related programs.
media : Mount points for media devices.


df -h : Gives information about the partitions.
-h : Human readable, ie. Prints the details in a way easily unstaandable by human beings.

df -h . : Give the details of the disk partition that contains the present working directory.

du -h : Prints the disk usage details for the current directory.

which <command>: Give the absolute path for the command / program.
Eg: which ls
/bin/ls

$PATH is an environment variable that contains the list of directories which has executable files in it. So if we give a command it will search all the folders in the $PATH variable and if it is there then it will get executed, else it will print and error “Command not found..”.

echo $PATH : Prints the content of PATH variable.

We can temporarily change the $PATH variable using export command.
Eg:
export PATH=/usr/local/bin:/bin:/usr/sbin
or
export PATH=$PATH:/usr/sbin

$HOME – Contains the home folder for current user.
Eg: echo $HOME

file <file_name> : Displays the type of the file.

cmp <file_1> <file_2> : Compares two files

Searching in Linux:

Wild char symbols:
* : Matches any number of characters
? : Matches exactly one character.
[a-z] : Matches any character within the specified range.

Eg: ls *.txt
mv ./abc/*.txt ./abc/*.c


find <path> -name <search_string>
find <path> -size <size>

Eg: find /temp -name “abc.txt”
find . -size +50k

locate <search_string> : Similar to find but more friendly and less efficient.

~/.bash_history : is a file that contains the bash usage history.

grep: Command used to filter input lines and return only some patterns.

Eg: grep find ~/.bash_history
grep apple ./fruits.txt

NB: /usr/share/dict/words is a dictionary containing all the English words

Eg: grep man /usr/share/dict/words

cat : Concatenates and displays the output of one or more files to the screen. Output displayed in an uncontrolled way.

more : Displays the output with scrolling downward option.

nano : A simple text editor.

head : Display first few lines of a text file.

tail : Display last few lines of a text file.


File and Directory Permissions:

For each file any users can be classified into any of the three categories:
  • u – User / Creator of the file
  • g – Group User
  • o – Any other user

ls -l gives a detailed listing along with the user and privilege details. There are separate privileges for read(r), write(w) and execute(x) for user, group user and other users.

chmod : Used to change the user privileges of any file.
Use -r or –recursive to apply privileges excursively to all subfiles in a directory.
Eg: chmod u+x abc.txt #Add user the privilege to execute.
chmod ug+rwx abc.txt #Add user and group user the privilege to read,write andexecute.
chmod o-x abc.txt #Deducing the power of other user to execute the file.
chmod 777 abc.txt #Give all privileges to all categories of users.

Processes:

A program executing in memory is called a process.
Using a terminal we can execute a process in:
  • Foreground
    OR
  • Background

<regular_command> : Runs the command in background.

<regular_command> & : Runs the command in background.

jobs : Command to display all the jobs running in background.

Ctrl + Z : Suspends a program running in foreground.

Ctrl + C : Terminate and quit a process running in foreground.

%n : Every process running in background has got a unique number, we can get that using job command.

bg <%n> : Reactivate a suspended program in background.

fg <%n> : Puts the job back in background.

kill <%n> : Terminates a background process.


  • All the process has got a unique identification number called PID or Process ID.
  • A process is being created by another by the process of forking in which the address space of one process is being cloned.
  • Every process also have a Parent Process Id or PPID.

ps : Displays the processes created by the current user.
-f : Option to display PPID as well.
-e or -A : Display all the system process as well.
-u <username> : diplay all the processes created by any particular user.
Eg:
ps -e | grep tty
ps -e

kill <PID> :Terminates a process.

top : Displays the currently running tasks and their CPU utilization.

nohup <command> : Executes the command even if we log out of the system and writes the output to the file nohup.out.
Eg: nohup wget -c www.athena.nitc.ac.in/file.txt &
NB: wget is used to download a file.

pstree : Displays all currently running processes along with their parent child relationships.


time <command>: Executes the command and displays how much time it takes.

netstat : Displays the current network usage and traffic.

vmstat : Displays the current virtual memory usage.

sleep <seconds> : Do nothing for sometime.
Eg: sleep 5
(sleep 1800 ; echo “Lunch Time”) &


I/O Redirection:
> : Used to direct the output to a file.
>> : Used to append the output to a file.
| : Used to take the output of one command to another.

Eg: ls -al > ls.list
top > current.txt


Package Managers:

Redhat Package Manager : RPM

installing an rpm:
rpm -Uvh <path>
-U : Upgrade
-v : Generate more verbose output
-h : Gives a progress bar of installation

To check whether a program is being installed:
rpm -qa | grep gimp

Uninstalling:
rpm -e application

Debian Package Manager : dpkg

To install an application:
sudo dpkg -i package.deb

To check version and details of an installed application:
dpkg -l application
OR
dpkg -l *application*

APT – Advanced Package Manager

sudo apt-get update : Will update the database with list of available packages.

sudo apt-get install package : Installs a new package.

sudo apt-get upgrade : Performs and upgrade.



ssh user@host : Secure Shell Login to a remote server

scp sort.cpp abijith_bcs10@athena.nitc.ac.in: : SSH File Copy

write user [tty] : Used to send messages to other users.

Using gcc:

gcc <filename.c> -o <output_filename>
./output_filename


Different Shells:

sh : Traditional Unix Shell or Bourne Shell
bash : Bourne Again Shell, the default linux shell
ksh : Korn Shell
csh : C-Shell
tcsh : Turbo C Shell

$SHELL : Environment variable that contains the current shell

/etc/shells - File containing the list of available shells.

Shell scripts starts with
#! /bin/bash
so that when they are executed, it will be using BASH by default.
Eg:

#! /bin/bash

echo “Hello World!..”

Save it as sample.sh and give chmod +x sample.txt
Execute it as: ./sample.sh

Tuesday, January 29, 2013

Matrix Addition in NASM

section .bss
  num: resw 1 ;For storing a number, to be read of printed....
  nod: resb 1 ;For storing the number of digits....
  temp: resb 2
  matrix1: resw 200
  matrix2: resw 200
  matrix3: resw 200
  m: resw 1
  n: resw 1
  i: resw 1
  j: resw 1
  
  
section .text
  msg1: db "Enter the number of rows in the matrix : "
  msg_size1: equ $-msg1
  msg2:  db "Enter the elements one by one(row by row) : "
  msg_size2: equ $-msg2
  msg3: db "Enter the number of columns in the matrix : "
  msg_size3: equ $-msg3
  
  msg_matrix1: db "First matrix : ", 10
  msg_matrix1_size: equ $-msg_matrix1
  
  msg_matrix2: db "Second matrix : ", 10
  msg_matrix2_size: equ $-msg_matrix2
  
  
  msg_matrix3: db "Second matrix : ", 10
  msg_matrix3_size: equ $-msg_matrix3

  
  tab: db  9 ;ASCII for vertical tab
  new_line: db 10 ;ASCII for new line
  
section .text
  global _start

_start:
  mov eax, 4
  mov ebx, 1
  mov ecx, msg1
  mov edx, msg_size1
  int 80h
  
  mov ecx, 0
  call read_num  
  mov cx, word[num]
  mov word[m], cx
  
  
  mov eax, 4
  mov ebx, 1
  mov ecx, msg3
  mov edx, msg_size3
  int 80h
  
  mov ecx, 0
  call read_num  
  mov cx, word[num]
  mov word[n], cx
  
  

  
  mov eax, 4
  mov ebx, 1
  mov ecx, msg2
  mov edx, msg_size2
  int 80h
  
  
  ;Reading each element of the matrix........
  mov eax, 0
  mov ebx, matrix1  
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop:
    mov word[j], 0
    j_loop:
 
 call read_num
 mov dx , word[num]
 ;eax will contain the array index and each element is 2 bytes(1 word) long
 mov  word[ebx + 2 * eax], dx
 inc eax    ;Incrementing array index by one....
     
 
 
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop
 
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop
  
  
  
  
  
  mov eax, 4
  mov ebx, 1
  mov ecx, msg2
  mov edx, msg_size2
  int 80h
   ;Reading each element of the matrix........
  mov eax, 0
  mov ebx, matrix2  
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop2:
    mov word[j], 0
    j_loop2:
 
 call read_num
 mov dx , word[num]
 ;eax will contain the array index and each element is 2 bytes(1 word) long
 mov  word[ebx + 2 * eax], dx
 inc eax    ;Incrementing array index by one....
     
 
 
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop2
 
  
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop2 
  
  
  
;Adding the two matrices ie. matrix3 = matrxi1 + matrix2
  mov eax, 0
  ;Initializing base pointers.....
  mov ebx, matrix1  
  mov esi, matrix2
  mov edi, matrix3
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop3:
    mov word[j], 0
    j_loop3:
 
 ;eax will contain the array index and each element is 2 bytes(1 word) long
 mov  dx , word[ebx + 2 * eax]
 add dx, word[esi + 2 * eax]
 mov word[edi + 2 * eax], dx
 
 inc eax    ;Incrementing array index by one....
     
 
 
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop3
 
  
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop3 
  
  
  
  
  
   mov eax, 4
   mov ebx, 1
   mov ecx, msg_matrix1
   mov edx, msg_matrix1_size
   int 80h
  
  
  
  ;Printing the  matrix1....
  mov eax, 0
  mov ebx, matrix1  
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop4:
    mov word[j], 0
    j_loop4:
 
   ;eax will contain the array index and each element is 2 bytes(1 word) long
   mov  dx, word[ebx + 2 * eax]   ;
   mov word[num] , dx
   call print_num
   
   ;Printing a space after each element.....
   pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, tab
     mov edx, 1
     int 80h    
   popa
   
   inc eax  
     
     
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop4
 
  pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, new_line
     mov edx, 1
     int 80h    
   popa
 
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop4
  
  
  
  
  
  
  
  
  
  ;Printing the final matrix2....
  
   mov eax, 4
   mov ebx, 1
   mov ecx, msg_matrix2
   mov edx, msg_matrix2_size
   int 80h
   
  mov eax, 0
  mov ebx, matrix2  
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop5:
    mov word[j], 0
    j_loop5:
 
   ;eax will contain the array index and each element is 2 bytes(1 word) long
   mov  dx, word[ebx + 2 * eax]   ;
   mov word[num] , dx
   call print_num
   
   ;Printing a space after each element.....
   pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, tab
     mov edx, 1
     int 80h    
   popa
   
   inc eax  
     
     
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop5
 
  pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, new_line
     mov edx, 1
     int 80h    
   popa
 
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop5
  
  
  
  
  
    ;Printing the final matrix....
   mov eax, 4
   mov ebx, 1
   mov ecx, msg_matrix3
   mov edx, msg_matrix3_size
   int 80h
  mov eax, 0
  mov ebx, matrix3  
  
  mov word[i], 0
  mov word[j], 0
  
  
  i_loop6:
    mov word[j], 0
    j_loop6:
 
   ;eax will contain the array index and each element is 2 bytes(1 word) long
   mov  dx, word[ebx + 2 * eax]   ;
   mov word[num] , dx
   call print_num
   
   ;Printing a space after each element.....
   pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, tab
     mov edx, 1
     int 80h    
   popa
   
   inc eax  
     
     
 inc word[j]
 mov cx, word[j]
 cmp cx, word[n]
 jb j_loop6
 
  pusha
     mov eax, 4
     mov ebx, 1
     mov ecx, new_line
     mov edx, 1
     int 80h    
   popa
 
    inc word[i]
    mov cx, word[i]
    cmp cx, word[m]
    jb i_loop6
  

  
  

  
;Exit System Call.....
exit:
  mov eax, 1
  mov ebx, 0
  int 80h

  
  
;Function to read a number from console and to store that in num 
read_num:

  pusha
  mov word[num], 0
  
  loop_read:
    mov eax, 3
    mov ebx, 0
    mov ecx, temp
    mov edx, 1
    int 80h
    
    cmp byte[temp], 10
      je end_read
    
    mov ax, word[num]
    mov bx, 10
    mul bx
    mov bl, byte[temp]
    sub bl, 30h
    mov bh, 0
    add ax, bx
    mov word[num], ax
    jmp loop_read 
  end_read:
  popa
  
ret


;Function to print any number stored in num...
print_num:
  pusha
  extract_no:
    cmp word[num], 0
    je print_no
    inc byte[nod]
    mov dx, 0
    mov ax, word[num]
    mov bx, 10
    div bx
    push dx
    mov word[num], ax
  jmp extract_no

  print_no:
    cmp byte[nod], 0
    je end_print
    dec byte[nod]
    pop dx
    mov byte[temp], dl
    add byte[temp], 30h


    mov eax, 4
    mov ebx, 1
    mov ecx, temp
    mov edx, 1
    int 80h
    
    jmp print_no
    
  end_print:   
  popa
ret