Sei sulla pagina 1di 6

MP SYSTEMS

URSM-COLLEGE OF ENGG.

1/6

ARITHMETIC C OMMANDS AND THE INTEL 8086 FLAG BITS


1. THE INTEL 8086/8088 STATUS REGISTER (FLAG CONFIGURATION)
Hex
h
Bin
b b b
0 1 FLAGS

b
-

h
b b
NV UP
OV DN
O
D

h
b b
b b b
DI T PL NZ EI T NG ZR I
T S
Z

h
b
NA
AC
A

b
-

b
PO
PE
P

(0) No oVerflow
(1) OVerflow

b
-

b
NC
CY
C

No Carry
CarrY

(0) UP increment
(1) DowN (decrement)

Parity Odd
Parity Even

(0) Disable Interrupt


(1) Enable Interrupt

No Auxiliary carry
Auxiliary Carry

(0) PLus
(1) NeGative

No Zero
ZeRo

NOTE: T (trap) enables trapping through an on-chip debugging feature (programenabled error trapping); if enabled (1) the P interrupts the flow of the program on
conditions as indicated by the debug/control registers, otherwise it is disabled.

2. ARITHMETIC COMMANDS FOR INTEL 8086


DEBUG has another command which executes an entire program without stopping until
the end. This is the g (go) command and at default the processor assumes that it should
start program execution at the memory address 0100H indicated by the instruction pointer
(IP). If that is not where you want to start, (such as when you want to execute a program
for the second time), this can be accomplished as follows:
start by changing IP to 0100 then,
execute a g command at the DEBUG prompt.

-rip
IP hhhh
:0100
-g

next to - (DEBUG prompt) type rip & press <ENTER> key


screen display after pressing <ENTER> key
next to : enter 0100
enter the go command

The other way is to specify a starting point as part of the g command like

-g =0100
When you use the go command, the processor has to know where to stop. An assembly
program must terminate using RET (return) command or the MS-DOS interrupt function
INT 20 to stop program execution and return to DEBUG prompt.

FMFernando

7/28/11

MP SYSTEMS

URSM-COLLEGE OF ENGG.

2/6

HEX Addition
1. For example, the assembly program to add 49H (or decimal 73) and 1EH (decimal 30)
may be as follows:
xxxx:0100 MOV AL,49
xxxx:0102 ADD AL,1E
xxxx:0104 RET

;store dec 73
;add dec 30
;(or replace RET with INT 20)

Using DEBUGs go command with starting and stopping or breakpoint 0100 to 0104
prior to executing the RET (or INT 20) command at 0104, enter

-g =0100 0104
These will cause program execution to start at address 0100H and to stop at address
0104H. The contents of the register and flags will be automatically displayed. The same
task can be accomplished (only if IP is set at address 0100H) using

-g 0104
-rf

show flags or status registers only

A sample program interaction is shown here. (Underlined text are user-entered at


DEBUG prompt)

Examining the flags from right to left; (NC) means there was no carry from the 8th (the
MSB of low byte) to the 9th bit (the LSB of the high byte). The result (if converted to
binary 0110 1110) was parity odd (PO) since it has odd number of 1s. There was an
auxiliary carry (AC) that is, from 4th to 5th bit (which is also very useful in BCD
numbers). There was no zero (NZ) because the answer was not zero. The answer was
positive or plus (PL) because there was no 1 in the 8 th bit. (EI) enable interrupt
request and the auto-increment (UP) are used by the DI and/or SI registers during string
instructions. There was no overflow (NV) or out of range; for 8-bit signed binary
numbers the range is -128 to +127. Note that if you compare the flag bits before and after
program run, a change was only in auxiliary carry (AC) flag.
2. Assemble and run the following program in DEBUG. The flag bit that will change
should be the zero flag that is from an initial state (NZ) to (ZR).
xxxx:0100 MOV AL,C9 ;negative 55
xxxx:0102 ADD AL,37 ;positive 55 is added
xxxx:0104 RET

-g 104
-rf

FMFernando

7/28/11

MP SYSTEMS

URSM-COLLEGE OF ENGG.

3/6

3. Since the valid 8-bit range is +127 to -128 and for 16-bit range, +32767 to -32,768.
Modify your previous program for 8-bit overflow range: 123 + 111 = 234 in decimal
notation. In hex, 7B + 6F = EA. There will be an auxiliary carry (AC), a negative sign
bit (NG), and that the overflow (OV) bit is set. The sum in hex (EA) is the correct answer
if you are using unsigned binary numbers! For signed binary numbers hex EA in decimal
is -22 and this is not the correct answer since it exceeded the 8-bit signed binary
numbers.
A sample program interaction is shown.

BCD Addition
Because of differences in the way binary and decimal numbers round, and because
numeric output to humans is usually decimal, it is sometimes helpful to do addition using
binary coded decimal. The processor encounters problems with BCD addition but this is
corrected or adjusted by way of packed BCD numbers using the command decimal
adjust (DAA). See the following example.
1. Decimal (BCD)
0100 0111 (BCD)
+ 0011 0110 (BCD)
1000 0011 (BCD)

4710
3610
8310

2. Binary/Hex
0100 0111
+ 0011 0110
=
0111 1101

4716
3616
7D16

Encode the following assembly code using DEBUG.

Next, execute the program at the DEBUG prompt using this instruction:

-g =0100 011B

FMFernando

7/28/11

MP SYSTEMS

URSM-COLLEGE OF ENGG.

4/6

Pay attention to the final contents of AX = 0083 (this is the result of BCD addition) and
BX = FA92 including the status registers. Other important information specially prior to
these can be shown using the dump (d) command starting at RAM address 0140 until
01AF by entering:

-d 01A0 01AF
Screen output should be

XXXX:01A0 7D 06 72 83 92 72 00 00-00 00 00 00 00
These means
RAM Address 01A0
RAM Address 01A1
RAM Address 01A2
RAM Address 01A3
RAM Address 01A4
RAM Address 01A5

binary/HEX sum = 7D
binary/HEX flags (low byte) = 06
binary/HEX flags (high byte) = 72
BCD sum = 83
BCD flags (low byte) = 92
BCD flags (high byte) = 72

To decode the flag bits consider RAM address 01A5 and 01A4 in the high-byte and lowbyte sequence. This is equivalent to

Hex
Bin
0
1

7
0
-

1
-

1
-

1
-

72 92 = 0111 0010 1001 0010


2
9
0
0
1
0
1
0
0
NV UP DI T PL NZ OV DN EI T NG ZR -

2
1
NA
AC

0
-

0
PO
PE

1
-

0
NC
CY

This means flags affected are NV, UP, EI, NG, NZ, AC, PO, and NC.

Subtraction
Subtraction is the opposite of addition and can be done using the SUB command as
follows:
xxxx:0100 MOV AL, 7F
xxxx:0102 SUB AL, 80
xxxx:0104 RET
The sample program interaction follows:

FMFernando

7/28/11

MP SYSTEMS

URSM-COLLEGE OF ENGG.

5/6

1-Byte and 2-Byte Multiplication


If two 8-bit (1 byte) hexadecimals are to be multiplied as in 1E x FC (which is equivalent
to 1DBB) as in immediate mode multiplication
MOV AL,1E
MUL AL,FC
RET
This is NOT ALLOWED! Instead use the following code sequence
MOV AL,1E
MOV BL,FC
MUL BL
RET
Notice the multiplicand is placed in AL and then the multiplier in BL, so we only need
MUL BL and the processor assumes that the firs number is in AL. There are only two
flags that have meaning after MUL command overflow and carry flags, such that when
AH is 00 then, both these flags are cleared. Any other result in AH causes both of these
flags to be set.
A 2-byte (16 bits) multiplication problem is shown here

FFE2
12D3
12D0 CB46

The equivalent assembly program is


MOV AX,FFE2
MOV BX,12D3
MUL BX
RET
The product of the 16-bit multiplication is found in DX = 12D0 and AX = CB46
combination.

Integer Division
When division is done, the dividend must be twice as wide (16 or 32 bits) as the divisor
(8 or 16 bits). Suppose 564A (dividend) is divided by FB (divisor) the result in integer
format is 58 (the quotient) found in AL and the remainder 2, is found in AH. Use the
following code:
MOV AX 564A
MOV BL,FB
DIV BL
RET
Another example is:
MOV DX,20E2
MOV AX,8DF4
MOV BX,45CE
DIV BX
RET

FMFernando

This means the 32-bit dividend is 20E2 8DF4


The divisor is a 16-bit hex 45CE
Quotient is found in AX= 789A
with a remainder DX= 0008

7/28/11

MP SYSTEMS

URSM-COLLEGE OF ENGG.

6/6

PROBLEM:
1. With a computer and DEBUG utility program, store the unsigned hex 67 and 23 in
two consecutive RAM address. Write an assembly code to find the sum of these two
numbers and store the result in a free RAM address. (HINT: One possibility is first use
the DEBUG enter e command as in -e 0180 67 23 00 00 to place 67,
23, 00, 00 into RAM address 0180,

0181, 0182, and 0183,

respectively. Then assemble and run the appropriate code to solve this problem.)
2. Determine which flags are altered by subtracting the signed hex 4D from 7F. Write a
program to store all values required including flag registers in appropriate RAM
addresses.
3. Divide 12D0CB46 by FFE2 and show on-screen the computed value.
4. Store in RAM the hex value 20E28DF4 as the dividend to find the quotient when

789A is the divisor.


5. Assume X = 25,394,410 and Y = -12810. Write a program to calculate
Z = (X/Y) - 4( X + 2Y ).

FMFernando

7/28/11

Potrebbero piacerti anche