Register and Variable declaration in Assembly Language EMU8086

Here we will know about the Registers we use in Assembly Language and will also know how to declare variable in Assembly Language emu8086

Basically the machine works with the registers. The register stores data or value we want. When we declare variable and store data in it, the machine can not work with the data directly. Behind the scene it actually takes the data in it's internal memory which means it stores data in it's register and then works with this. So, it is better to store data in register when we write program in assembly language. But there is a limitation that the register can not store large amount of data and registers are limited. In assembly language , there are maximum size of 32 bit register. So, when we need to work with large amount of data we have to declare variables and use them. But when we need to run operations with these data we should took them in register one by one.


I think you just got a basic idea about registers in assembly language. We will now learn this step by step. First of all please take a look in the assembly registers that we will use in our programming.

Register in assembly language 
Some Registers

Did you understood something? If you not, no problem, we will describe them in a few moments.

'EAX' is a 32 bit register. If we need to work with a 32 bit data we will use this. But if we need to work with a 16 bit data, then we will use 'AX' register which is a half part of 'EAX' register. Again 'AX' register has two parts, one is 'AH' and other one is 'AL' and each of these are 8 bit register.
Similarly EBX, ECX, EDX are 32 bit registers and BX, CX, DX are 16 bit registers. Now please see the picture again .
I think you are now clear about  the registers. Now we will discuss about the command of register for input and output. In assembly language input and output are basically an interrupt . We occur this interrupt by calling 'INT 21H' command. Before this interrupt we should find out what we are going to do. Interrupts are three types, single character input, single character output and show string as output. Based on our operation we should keep value in AH register first and then call interrupt. Such as if we put value 1 in our AH register and call interrupt it will open the command prompt to take a single character input. 
                     MOV AH, 1
                     INT 21H

 Again if we put value 2 in AH register and call an interrupt and it will print single character as output. We will discuss about the output later.
                     MOV AH, 2
                     INT 21H

 Again if we put value 9 in AH register and call an interrupt it will print the string as output.                                        MOV AH,9
                     INT 21H

I think you have got this idea.

Now let's talk about the storage or registers of input and output. Our input is always stored in the 'AL' register and printing output is shown from the 'DL' register for single character and DX register for string output.

Now we will discus about the variable declaration method or the way of declaring different kind of variables in assembly language emu8086. Like other programming language, we need three things for it: variable name, data type and initial value.

                                    variable_name    data_type      value

Example:                     myvariable    DB      10

If you want to declare the variable with initial null value, then we should use '?' character like this:

                             myvariable    DB    ?

Generally we use two types of data in assembly language code, DB (Data Byte) and DW (Data Word)
If we want to keep a message (string) in variable then it should be like:

                                 myvariable    DB   "Hello world $"

*Remember to put down '$' sign at the end of the string or you may get some garbage output. That's it, hope you have understood the basic concepts about variables and registers in assembly language. If you have any query please put it in the comment section.


For simple input and output in assembly language click here

Comments

  1. Hello, Why are we putting $ sign, to show that when we take a single character , then we should terminate inputting? And if we specified
    myvariable DB 0AH, 0DH , "Initial Value",'$'
    what is this doing? Why do we need 0AH and 0DH? Are they the AH and DH registers or some hexadecimal values?
    Thank you

    ReplyDelete
    Replies
    1. $ shows the end point of the string, means that string has ended.

      Delete

Post a Comment

Popular posts from this blog

How to Declare array in Assembly languages emu8086

How To Print New Line in Assembly Language emu8086

Simple Input and output in assembly Language EMU8086