Saturday, 31 October 2020

Accessing variables in 8086 Assembly Language

 Consider following set of variables declared


Num dw 0x98AD

Num2 dw 0x562B

Num3 dw 0x127A


To access data from these variables, we can use any of three variables (Num, Num2, Num3) as pointer to the memory and access all data by adding or subtracting offset values to the addresses. 


For instance, if you have address of Num2 and you want to access other values using this address as pointer, we can use following instructions;


Mov ax, [Num2];. AX=562B

Mov bx, [Num2+2];. BX=127A

Mov cx, [Num2-2];. AX=98AD

Mov dx, [Num2+1];. AX=7A56


In a similar way, we can use other variables as pointers and access any memory location. 

Flag register 8086

Here’s a quick review of iapx8088 processor flags:

Zero flag 

The zero flag is set "1" whenever the result of an (arithmetic or logical) operation is zero. 

For example, 

Mov al,5

Add al -5

These two instructions will produce result 0 and thus will set zero flag, ZF =1.


Also, for following example

Mov al,255

Add al,1

These instructions will produce result 256 which requires 9 bits (1 0000 0000) to store. Least 8 bits are stored in AL register causing the result to be zero in AL, hence the ZF =1. 9th bit of the result is stored in Carry flag.


Carry flag

The Carry flag is set when an operation generates a carry out of the highest bit of the destination operand.

In other words Carry flag is set "1" when an arithmetic or logical operation produces a result greator than the destination operand size.

For example,

Mov al,245

Add al,11

Result 256 can't be placed in one byte register hence the CF becomes 1.


For two byte operands ax,bx,cx etc., the CF becomes 1 when result exceeds the 16 bit destination operand.


• The Sign flag is a copy of the high bit of the destination operand, indicating that it is negative if set and positive if clear. (Zero is a positive number).

• The Overflow flag is set when an instruction generates a result that is outside the signed range of the destination operand.

• The Parity flag is set When an instruction generates an even number of 1's in the low byte of the destination operand.

Effect of ADD and SUB instructions on Flag register-Assembly Language for 8086 processor

Flag Register NOTE: ONE OR MORE FLAGS MAY GET SET OR RESET AFTER AN ARITHMETIC LOGIC INSTRUCTION MOV INSTRUCTION DOESN’T AF...