CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions ©...

19
CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved. 5/27/2012 1

Transcript of CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions ©...

Page 1: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

CIS 020 Assembly Programming

Chapter 12 - RR-Format Instructions

& more RX-Format Instructions

© John Urrutia 2012, All Rights Reserved.5/27/2012 1

Page 2: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

ObjectivesSyntax & Use of RR-Format instructionsRegister ComparisonsBinary or Fixed-point Multiplication / DivisionCondition Code branching

© John Urrutia 2012, All Rights Reserved. 25/27/2012

Page 3: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Register to RegisterRR instructions are the most efficient and are

used for comparisons and arithmetic between general purpose registers.

Most common RR instructions are of the form □R where □ is a letter representing the function and the R represent the register or register-pair.

□ can be:

© John Urrutia 2012, All Rights Reserved. 35/27/2012

A - Add D - Divide N - AndB - Branch L - Load O - OrC - Compare M - Multiply S - Subtract

X - Exclusive Or

Page 4: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Register to RegisterThere are 57 RR instructions

All RR instructions are 2 bytes long with the following syntax

© John Urrutia 2012, All Rights Reserved. 45/27/2012

RR Op Code R1 R20-7 8-11 12-15

First Halfword

OPERATION OPERANDS# #R R R 1 , R 2

Page 5: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Register to RegisterThe Load Register instruction

Copies the sending Register, Operand 2 to the receiving Register, Operand 1.

© John Urrutia 2012, All Rights Reserved. 55/27/2012

LABEL OPERATION OPERANDS1 # #I 1 L R R 1 , R 2

BEFORE AFTERI 1 R 1 X'????????' R 1 X'1BEAD4CD'

R 2 X'1BEAD4CD' R 2 X'1BEAD4CD'

Page 6: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Register to RegisterThe Add Register instruction

Adds in binary format, the sending Register, Operand 2 to the receiving Register, Operand 1.

© John Urrutia 2012, All Rights Reserved. 65/27/2012

LABEL OPERATION OPERANDS1 # #I 1 A R R 1 , R 2

BEFORE AFTERI 1 R 1 X'6FC32A20' R 1 X'8BADFEED'

R 2 X'1BEAD4CD' R 2 X'1BEAD4CD'

Page 7: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Register to RegisterThe Subtract Register instruction

Subtracts in binary format, the sending Register, Operand 2 to the receiving Register, Operand 1.

© John Urrutia 2012, All Rights Reserved. 75/27/2012

LABEL OPERATION OPERANDS1 # #I 1 S R R 1 , R 2

BEFORE AFTERI 1 R 1 X'6FC32A20' R 1 X'53D85553'

R 2 X'1BEAD4CD' R 2 X'1BEAD4CD'

Page 8: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

RR & RX InstructionsThe Comparison instructions - C & CR

Compares a registers 4 bytes algebraically, either to a Register or Fullword.

Register can be 0 through 15Parameter should be on a fullword boundary.

Failure to do this will slow down the instruction

© John Urrutia 2012, All Rights Reserved. 85/27/2012

LABEL OPERATION OPERANDS1 # #I 1 C R R 1 , R 2I 2 C R 2 , O U T

O U T D C F ' 5 7 0 0 5 '

BEFORE AFTERI 1 R 1 X'55555555' R 1 X'55555555' CC=2

R 2 X'00000000' R 2 X'00000000'I 2 O U T X'0000DEAD' O U T X'0000DEAD' CC=1

Page 9: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

RR & RX instructions

The Condition Code is set after all arithmetic and comparison instructions.

If numeric values are being compared the results can be tested using the following branch instructions

© John Urrutia 2012, All Rights Reserved. 95/27/2012

BZ - branch 0 BNZ - branch not 0BM - branch MINUS BNM - branch not MIN.BP - branch Positive BNP - branch not Pos.

BO - branch Ones

Page 10: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point Multiplication

When multiplying, the product can never exceed the number of digits being multiplied.Registers have a fixed 32 bits. When

multiplying 32 bits * 32 bits the result is 64 bits and can’t be stored in a single register.

For Fixed-point Multiplication the result is stored in a “Register Pair” consisting of an even numbered and sequentially odd numbered pair of Registersi.e. – R6 & R7

© John Urrutia 2012, All Rights Reserved. 105/27/2012

Page 11: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point MultiplicationThe M and MR instructions

Multiplies the odd numbered register in the register pair of Operand 1, by either 4 consecutive bytes or by the specified register in Operand 2.

The product is stored in the odd numbered register of the pair and overflow is in the even numbered register

Operand 2 parameter should be on a fullword boundary.Failure to do this will slow down the instruction

Incorrect reference to the even-odd paired registers will cause a specification ABEND S0C6

© John Urrutia 2012, All Rights Reserved. 115/27/2012

Page 12: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point MultiplicationThe M and MR instructions

Operand 1, even-odd register pair. Odd numbered register contains the Multiplicand

Operand 2, 4 Byte reference / fullword or Register Contains the Multiplier

Product replaces value in the even-odd register pair.

© John Urrutia 2012, All Rights Reserved. 125/27/2012

LABEL OPERATION OPERANDS1 # #

L R 5 , = F ' 4 0 9 6 'I 2 M R 4 , M U L T

M U L T D C F ' 2 1 8 4 5 '

BEFORE AFTERI 2 M U L T X'00005555' M U L T X'00005555'

R 5 X'00001000' R 5 X'05555000'

Page 13: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point MultiplicationThe M and MR instructions

© John Urrutia 2012, All Rights Reserved. 135/27/2012

LABEL OPERATION OPERANDS

1 # #

L R 7 , = F ' 8 0 8 0 8 0 'L R 6 , = F ' 0 4 0 4 0 4 '

I 1 M R R 6 , R 6

BEFORE AFTERI 1 R 6 X'00009DD4' R 6 X'00000007'

R 7 X'000C5490' R 7 X'9A125740'

Page 14: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point MultiplicationThe M and MR instructions

Square of R7

© John Urrutia 2012, All Rights Reserved. 145/27/2012

1 # #

L R 7 , = F ' 8 0 8 0 8 0 'L R 6 , = F ' 0 0 0 0 0 0 '

I 1 M R R 6 , R 7

BEFORE AFTERI 1 R 6 X'00000000' R 6 X'00000098'

R 7 X'000C5490' R 7 X'096ED100'

Page 15: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point DivisionThe D and DR instructions

Divides the even-odd register pair (64 bits) of Operand 1, by either 4 consecutive bytes or by the specified register in Operand 2 (32 bits).

The quotient (32 bits) is stored in the odd numbered register of the pair and remainder (32 bits) is in the even numbered register

Operand 2 parameter should be on a fullword boundary.Failure to do this will slow down the instruction

Incorrect reference to the even-odd paired registers will cause a specification ABEND S0C6

© John Urrutia 2012, All Rights Reserved. 155/27/2012

Page 16: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point DivisionWhen dividing, quotients exceeding the 32 bit limit

or dividing by zero will trigger a Divide Exception (ABEND S0C9).

The sign of the division is determined algebraically and is based on the dividend and divisor

For negative Dividends ensure the correct sign by using the following:

© John Urrutia 2012, All Rights Reserved. 165/27/2012

LABEL OPERATION OPERANDS

1 # #

I 1 L R 6 , D I V I D E N DI 2 S R D A R 6 , 3 2

Page 17: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary/Fixed-point DivisionThe D and DR instructions

© John Urrutia 2012, All Rights Reserved. 175/27/2012

LABEL OPERATION OPERANDS

1 # #

I 1 L R 6 , D I V I D E N DI 2 S R D A R 6 , 3 2I 3 D R R 6 , R 8

D I V I D E N D D C F ' - 6 5 5 3 6 '

BEFORE AFTERI 1 R 6 X'????????' R 6 X'FFFF0000'I 2 R 6 X'FFFF0000' R 6 X'FFFFFFFF'

R 7 X'????????' R 7 X'FFFF0000'I 3 R 6 X'FFFFFFFF' R 6 X'FFFFFF9C'

R 7 X'FFFF0000' R 7 X'FFFFFDEC'R 8 X'0000007B' R 8 X'0000007B'

Page 18: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary Halfword InstructionsJust like the binary fullword instructions:

Add an H

© John Urrutia 2012, All Rights Reserved. 185/27/2012

A -Add L -LoadC -Compare M -MultiplyS -Subtract ST -Store

AH -Add LH -LoadCH -Compare MH -MultiplySH -SubtractSTH -Store

Page 19: CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Binary Halfword InstructionsRegisters using halfword instructions always

refer to the low order 2 bytes of the registerBecause multiplying halfwords will never

exceed fullword capacity there is no need for register pairs

© John Urrutia 2012, All Rights Reserved. 195/27/2012