Microprocessor Systems: Addition, Subtraction and Flags in EE222, Essays (university) of Microprocessor and Assembly Language Programming

This document from the EE222 – Microprocessor Systems course explores addition, subtraction, and the flags used in these operations. various forms of addition, such as register addition, immediate addition, and memory-to-register addition. It also explains the role of flags like carry (C), parity (P), zero (Z), sign (S), and overflow (O) in arithmetic and logic instructions. The document uses examples from the Intel Microprocessors textbook to illustrate these concepts.

Typology: Essays (university)

2020/2021

Uploaded on 03/27/2021

shehroze-talat
shehroze-talat 🇵🇰

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Addition, Subtraction
EE222 Microprocessor Systems
Arbab Latif
Spring 2021
Resources:
The Intel Microprocessors: Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey
(Section 5.1)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Microprocessor Systems: Addition, Subtraction and Flags in EE222 and more Essays (university) Microprocessor and Assembly Language Programming in PDF only on Docsity!

Addition, Subtraction

EE222 – Microprocessor Systems Arbab Latif Spring 2021 Resources: The Intel Microprocessors: Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey ( Section 5.1 )

5 - 1 ADDITION, SUBTRACTION AND COMPARISON

  • The bulk of the arithmetic instructions found in any microprocessor include addition, subtraction, and comparison.
  • Addition, subtraction, and comparison instructions are illustrated.
  • Also shown are their uses in manipulating register and memory data.

List of Each Flag bit, with a brief

description of function.

  • C (carry) holds the carry after addition or borrow after subtraction. - also indicates error conditions
  • P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity; logic 1 for even parity. - if a number contains three binary one bits, it has odd parity; If a number contains no one bits, it has even parity
  • A (auxiliary carry) holds the carry (half-carry) after addition or the borrow after subtraction between bit positions 3 and 4 of the result.
  • Z (zero) shows that the result of an arithmetic or logic operation is zero.
  • S (sign) flag holds the arithmetic sign of the result after an arithmetic or logic instruction executes.
  • T (trap) The trap flag enables trapping through an on-chip debugging feature.
  • IOPL used in protected mode operation to select the privilege level for I/O devices.
  • NT (nested task) flag indicates the current task is nested within another task in protected mode operation.
  • RF (resume) used with debugging to control resumption of execution after the next instruction.
  • VM (virtual mode) flag bit selects virtual mode operation in a protected mode system.
  • AC, (alignment check) flag bit activates if a word or doubleword is addressed on a non- word or non-doubleword boundary.
  • VIF is a copy of the interrupt flag bit available to the Pentium 4– (virtual interrupt)
  • VIP (virtual) provides information about a virtual mode interrupt for (interrupt pending) Pentium. - used in multitasking environments to provide virtual interrupt flags

Addition

  • Addition (ADD) appears in many forms in the microprocessor.
  • A second form of addition, called add-with- carry , is introduced with the ADC instruction.
  • The only types of addition not allowed are memory-to-memory and segment register. - segment registers can only be moved, pushed, or popped
  • Increment instruction (INC) is a special type of addition that adds 1 to a number.

Register Addition

  • When arithmetic and logic instructions execute, contents of the flag register change. - interrupt, trap, and other flags do not change
  • Any ADD instruction modifies the contents of the sign, zero, carry, auxiliary carry, parity, and overflow flags. - Only the flags located in the rightmost 8 bits of the flag register and the overflow flag 0000 03 C3 ADD AX,BX 0002 03 C1 ADD AX,CX 0004 03 C2 ADD AX,DX

Memory-to-Register Addition

  • Moves memory data to be added to the AL (and other) register.

Array Addition

  • Memory arrays are sequential lists of data.
  • 10 Byte data [0-9]
  • Add content of array element 3,5 and 7

Increment Addition

  • The INC instruction adds 1 to any register or memory location, except a segment register.
  • The size of the data must be described by using the BYTE PTR, WORD PTR, DWORD PTR, or QWORD PTR directives.
  • The assembler program cannot determine if the INC [DI] instruction is a byte-, word-, or doubleword-sized increment.

Addition-with-Carry

  • ADC) adds the bit in the carry flag (C) to the operand data. - mainly appears in software that adds numbers wider than 16 or 32 bits in the 80386–Core - like ADD, ADC affects the flags after the addition