**Assembly Programing- Lets Start ! **

There is a misconception about the language, people think that learning assembly is not easy !, they think people who writes code in assembly are Hackers !, wow this sounds super crazy. It takes ages to master assembly language.If you browse through the online / offline book shelves you would hardly find a book explaining about assembly.

Removing the miconception about the subject, it is necessary to learn assembly before jumping to learn HLL, the fact is that there are many alogorithms that you can implement in assembly rather than HLL. It would take a while to become expert on assembly but you would interact closely with the compiler and understand how the compiler handles your data. As i said in my earlier blog , debugging would only be achieved when you understand HLL and Assembly.

**Number System **

It is important to understand the number systems to get good understanding of how data is handled by computers. Most operating systems uses binary number system to decimal data. So discussing about the binary number system would be real worth.

Computers uses binary value to represent values, and states ( in electronics ). So there are 2 conversions always possible

a) Decimal to Binary

b) Binary to Decimal

I would follow the method which is easy to understand

a) **Binary To Decimal Convertion**: Converting a binary number into decimal is easy but not the vice versa which we will see with the examples.

Eg : What is the binary equivalent to 10110110

Binary uses powers of 2 , and the decimal equivalent of above number is

1*2(pow)7 + 0*2(pow)6 + 1*2(pow)5 + 1*2(pow)4 + 0*2(pow)3+ 1*2(pow)2+1*2(pow)1+0*2(pow)0

Decimal equivalent is 128+0+32+16+0+8+4+0 = 188

Please practice 5 different examples to understand and concept

b) **Decimal To Binary Conversion: **Ah!, this is tricky , but will play around with it. The task is to convert Decimal number to Binary equivalent. You can have your mathematical calculator handy for all the calculations, but knowing these both plays an vital part in debugging which is why I emphasize learning assembly basics.

Lets take an example ( larger the number , lengthy the math !) 7044.Now that we have number we should convert to binary equivalent

PS : We represent 0 or 1 with respect to locations

Method 1:

Step1 : analyze which is the closest 2 pow integer which match / fall near the number , in

Our example 2(pow) 12 = 4096 and 2(pow) 13 =8192 , so our number fall in

Between both, so I will take 2(pow)12 . Now write 1 representing 2(pow)12

Step2 : Minus 4096 from 7044 = 2948 , we need to find the closest to represent 2948

Step3 : 2(pow)11 is 2048 which is closest number 2948 , so represent this with 1 and we

Minus 2048 from 2948 = 900

Step4 : 2(pow)10 is 1024 which is greater than 900 , so represent this location as 0

Step5 : 2(pow)9 is 512 which is smaller than 900 , so represent this location as 1 and

Minus the value from 900 i.e 900 – 512 = 388

Step6: 2(pow)8 is 256 which is smaller than 388 , so represent this location as 1 and

Minus the value from 388 i.e 388 – 256 = 132

Step7: 2(pow)7 is 128 which is smaller than 132 , so represent this location as 1 and

Minus the value from 132 i.e 132-128 = 4

Step6: 2(pow)6 is 64 which is greater than 4 , so represent this location as 0

Step7: 2(pow)5 is 32 which is greater than 4 , so represent this location as 0

Step8: 2(pow)4 is 16 which is also greater than 4 , so represent this location as 0

Step9: 2(pow)3 is 8 which is again greater than 4 , so represent this location as 0

Step10: 2(pow)2 is 4 which is equal to 4 , so represent this location to 1, now value is 0

Step11: 2(pow)1 is 2 which is less than 0 , so represent this location to 0

Stpe12:2(pow)0 is 0 which is 1 , so represent this location to 0

So 7044 equivalent is 1101110000100

Method 2:

This method is useful to convert the deimal number to any other base numbersystem .i.e to binary, octal, hexadecimal…. etc

Step 1: Divide the given decimal number with the base of the system , and notedown the remainder.

Step 2: Divide the quotient with the base of the system & notedown the reaminder .

Step 3 : Continue this process until quotient is less than the divider .

Step 4 : Starting with the last quotient until the first remainder writedown all the reaminders , the resulting number gives you the equivivalant number in

the choosed based system .

For clear understanding follow the example given

Example : conversion of decimal number 20 to equivalant binary number:

1. Divide 20 with 2 , quotient =10 , remainder =0.

2. Divide 10 with 2 , quotient =5 , remainder =0.

**3. Divide 5 with 2 , quotient =2, remainder =1.**

** 4. Divide 2 with 2 , quotient =1, remainder = 0.**

** Starting with the last quotient until first remainder write the remainders one by one **

** **

** So the binary equivalant of 20 is = 10100**

**Exercise : Please perform the above steps and deduce for 1000, 3366, 6843**

** **

** **

This representation is very important while you are debugging. You might see the below patterns such as 00000110 which is equivalent to 6 and this representation completely depends on the machine architecture . I will be addressing the modes of operation of INTEL processor once I complete the basics of number system.

You might have read trillion times about the below conventions but they are very useful.

4 bit = A nibble

8 bit = 1 byte

16 / 32 bit = 1 word , this depends on the processor architecture.

Will discuss about INTEL modes of operation along with working with bits and bytes. Its already 1.00 am , time to sleep J