SAP 3 ARCHITECTURE

download SAP 3 ARCHITECTURE

of 5

Transcript of SAP 3 ARCHITECTURE

  • 7/23/2019 SAP 3 ARCHITECTURE

    1/5CENG03. COMPUTERSYSTEM ARCHITECTURE. SAP 3. esquiv

    AP 3

    P3 instruction set includes all the SAP 2 instructionss new instructions.

    SAP 3 Programming Model

    ote: The additional CPU registers, D, E, H and L areused for more efficient data processing.

    The F register stores flag bits: S (sign flag), Z

    (zero flag) and others.

    ADVANTAGE OF MORE CPU REGISTERS

    1. Programs can run faster2. Simplifies program writing

    ARITHMETIC INSTRUCTIONS

    ote: CY = CARRY if operation is ADDCY = CARRY if operation is SUB

    ote: The 8-bit sum S7S0 is stored in theaccumulator. The CY is stored in a special FFcalled CARRY FLAG.

    ote: The CY flag acts like the next higher bit of theaccumulator, i.e. CY = AB

    CARRY FLAG INSTRUCTIONS

    Note: There are two instructions that can be used control the carry flag.

    1. STC - SET CARRY-will set the CY flag if it is not sete.g. if CY=0, STC produces CY=1

    2. CMC - COMPLEMENT THE CARRY- complements the value of CY

    ADD INSTRUCTIONS

    ADD REG

    Example 1:

    A = 1111 0001

    E = 0000 1000

    Solution:

    1111 0001+ 0000 1000

    1111 10001

    Answer:

    Example 2:

    A = 1111 1111

    L = 0000 0001

    Solution:

    1111 1111+ 0000 00011 0000 0000

    Answer:

    A

    FC B C

    SL D E F

    H L

    CY A7 A6 A5 A2 A1 A0

    CY=0 A=1111 1001

    CY= 1 A=0000 0000

  • 7/23/2019 SAP 3 ARCHITECTURE

    2/5CENG03. COMPUTERSYSTEM ARCHITECTURE. SAP 3. esquiv

    ADC INSTRUCTIONS(ADC = Add with carry)

    ADD REG

    ample 1:

    A = 1000 0011

    E = 0001 0010CY = 1

    lution:

    1000 0011+ 0001 0010

    11001 0110

    swer:

    SUB INSTRUCTIONS

    SUB REG

    ample 1:

    A = 0000 1111

    C = 0000 0001

    lution:

    0000 1111- 0000 0001

    0000 1110

    swer:

    Example 2:

    A = 0000 1100

    C = 0001 0010

    Solution:

    0000 1100

    - 0001 00101 1111 1010

    Answer:

    SBB INSTRUCTIONS(SBB = Subtract with borrow)

    Note: It subtracts the contents of a specified registand the CY flag from the accumulator contents.

    Example 1:

    A = 1111 1111

    E = 0000 0010

    CY = 1

    Solution:

    1111 1111- 0000 0010

    11111 1100

    Answer:

    CY=0 A=1001 0110

    CY=0 A=0000 1110

    CY=1 A=1111 1010

    CY=0 A=1111 1100

  • 7/23/2019 SAP 3 ARCHITECTURE

    3/5CENG03. COMPUTERSYSTEM ARCHITECTURE. SAP 3. esquiv

    INCREMENTS

    INR REG

    ote: The INR instruction has no effect on the carryg, but it does affect the sign flags and zero flags.

    ample 1:

    B = 1111 1111, and

    The initial flags are

    S=1, Z=0, CY=0

    swer:

    DECREMENTS

    DEC REG

    ample 1:

    E = 0000 0000

    S=0, Z=1, CY=0

    swer:

    ROTATE ALL LEFT (RAL)

    Note: The CY flag is included in the rotation of bits

    Example 1:

    CY = 1

    A = 0111 0100

    Answer:

    ROTATE ALL RIGHT (RAR)

    Note: The CY flag is included in the rotation of bits

    Example 1:

    CY = 1

    A = 0111 0100

    Answer:

    B = 0000 0000S=0, Z=1, CY=0

    E = 1111 1111S=1, Z=0, CY=0

    CY=0A = 1110 1001

    CY MSB A LSB

    CY=0A = 1011 1010

    CY MSB A LSB

  • 7/23/2019 SAP 3 ARCHITECTURE

    4/5CENG03. COMPUTERSYSTEM ARCHITECTURE. SAP 3. esquiv

    ROTATE LEFT WITH CARRY (RLC)

    ote: This instruction will rotate the contents of thecumulator to the left and the MSB is saved in the CYg.

    ample 1:

    CY = 1

    A = 0111 0100

    swer:

    ROTATE RIGHT WITH CARRY (RRC)

    ote: The LSB is saved in the CY flag.

    ample 1:

    CY = 1A = 0111 0100

    swer:

    MULTIPLY AND DIVIDE BY 2

    Uses of rotate instructions:

    1. Parallel to serial and serial to parallel converof data.

    2. Has the effect of multiplying or dividing theaccumulator contents by a factor of 2.

    Note: With the carry flag reset, a RAL has the effecmultiplying by 2, while the RAR divides by 2.

    Example 1:

    RAL

    CY = 0

    A = 0000 0111

    Answer:

    Example 2:

    RAL

    CY = 0

    A = 0010 0001

    Answer:

    CY=0A = 1110 1000

    CY MSB A LSB

    CY=0A = 0011 1010

    CY MSB A LSB

    CY=0A = 0000 1110

    CY=0A = 0100 0010

  • 7/23/2019 SAP 3 ARCHITECTURE

    5/5CENG03 COMPUTERSYSTEM ARCHITECTURE SAP 3 esquiv

    ample 3:

    RAR

    CY = 0

    A = 0001 1000

    swer:

    ample 3:

    RAR

    CY = 0

    A = 0000 1100

    swer:

    Example program:

    Show a SAP 3 program that adds 700 and 400, withfinal answer stored in the H ad L registers.

    INSTRUCTION

    CY=0A = 0000 1100

    CY=0A = 0000 0110

    MVI A,

    00H

    MVI B,

    02H

    MVI C,

    BCH

    MVI D,

    O3H

    MVI E,

    84H

    ADD C

    ADD E

    MOV L, A

    MVI A,

    00H

    ADC B

    ADD D

    MOV H, A

    HLT