Tuesday, November 6, 2007

Assembly Language

Assembly language is a Second-Generation low level language made up form mnemonics which can be used instead of machine code.
The formate for this language generally consist in 4 parts:
  1. Label eg Start:
  2. Op Code eg mov
  3. Operands eg bx.8Oh
  4. Comments eg ;load character count.

Addressing Modes

Understanding assemlby language is intimitly ties up with addressing modes. These are related to physical attributes like the registers available and the word length, if, for example you have a single byte register in which to store information for a jump instruction, then you can jump a maximum of 2525 memory locations. Double the length of the location and you could jump 65636 locations or from +32767 to -32768 of you are using a 2's compliment system.

Register Addressing

When data is transferred from a source register to a destination register

Immediate Addressing

This is when the data appears immediately after the op code, as part of the instruction. Immediate addressing is a very convenient way of putting numbers into registers by specifying the number as one of the operands.

Direct Addressing

Direct addressing refers directly to a specific memory location.

labelop codeoperandscomments

mov

ax, [myData]

;an example of direct addressing

Here the contents of the memory location, in the case specified by a label named myData, is copied into the ax register.

Indirect Addressing.

Indirect addressing uses a number inside the register(usually an index register to point to the memory loaction of interest where the actual data can be found.

labelop codeoperandscomments

mov

ax, [bx]

;an example of indirect addressing

In this example the brackets around the bx register indicate that the memory location pointed to by the bx register, and not the actual number inside the bx register, will be used. In this case the data in the memory location pointed to by the bx register is copied to the bx register.

Indexed Addressing

For indexed addressing a number contained in one register is usually uded in combination with the number in another register to point to the actual memory location where the data can be obtained.

labelop codeoperandscomments

mov

ax, [bx + di]

;an example of direct addressing

In this example the number in the bx register is combined with the number in the di register. As with indirect addressing, the square brackets indicate that this points to the memory location from where the actual data to be put into the cx register can be obtained.

Base Register and Base Indexed Addressing.

labelop codeoperandscomments

ld

&10[ax]

;an example of base register addressing

movcx,[bx+di];an example of based indexed addressing

In the first entry an address is held in the base register, in this case the ax register, and an offset (the hex number 10) is added to it. The second entry is useful for handling arrays.

Example

By means of an example, show a typical use for a base indexed addresing mode



Solution

A classic example of indxed addressing is setting up an array un memory. Consider the two - dimentional array, as shown in thne following examaple.


This could be mapped onto the memory lacations as shown below.
A linear sequence of memory locations is mapped onto a 2 dimentional array by using 2 index registers, namly the base-index and destination-index registers
One register is used fr each dimention of the array. The example shows how th efith element of the array, ie. 22, is accessed by putting the base index register
to a value of 3, and the destination index register of value of 1. In this case the fith element(not to forget we start at 0) and the number 22 is placed in the
cx register.




Actual Address MEMORY Indexed Address
address + 0 10 Address + 0 + 0
address + 1 11 Address + 0 + 1
address + 2 12 Address + 0 + 2
address + 3 21 Address + 3 + 0
address + 4 22 Address + 3 + 1
address + 5 23 Address + 3 + 2
address + 6 31 Address + 6 + 0
address + 7 32 Address + 6 + 1
address + 8 33 Address + 6 + 2


Typical Assembly Language Instructions.

Instructions are made of:


  • Logical Operations - "And", "Or" and "Not"

  • Rotate Instructions - Shift left and Right

  • Arithmetical Instructions

  • Bit SET and bit RESET instructions

  • Program control instructions - like "jump"



  • Arithmatical Operations

    Typical of the operations are addition, subtraction, multiplication and divsion. The complexity of each operation depends
    on what is being done. For example, when dividing two numbers there will probably be an integer answer(called thequotient)
    and a remainder. When multiplying two numbers the register for holding the the two numbers to be multiplied will be held in smaller
    than the register needed of the answer.


    Logical Operations

    The logical operations include and, or, not and xor etc. These instructions operate in what is called BITWISE MODE,
    where each bit of a register is matched against the equivalent bit in another register. The and operation is particularly useful for
    MASKING.


    Masking

    When using the logical functions we can create a mask which wither lets a pattern of bits through, or blocks them.Masking is used
    extensively in assembly language to set or reset some of the bits without altering the patterns of other bits.

    No comments: