20
CIS 020 Assembly Programming Chapter 11 - Binary Operations Using RX-Format Instructions © John Urrutia 2012, All Rights Reserved. 5/27/2012 1

CIS 020 Assembly Programming Chapter 11 - Binary Operations Using RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121

Embed Size (px)

Citation preview

CIS 020 Assembly Programming

Chapter 11 - Binary Operations Using

RX-Format Instructions

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

ObjectivesFamiliarization with the General Purpose

RegistersSyntax & Use of some RX-Format instructionsConversion to Binary format from Decimal

formatConversion to Decimal format from Binary

formatBoundary Alignment

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

General Purpose RegistersAs we will see there are multiple instructions

that do the similar thingsRegister instructions are the most efficient

because they are part of the CPUIn the 390 architecture there are:

16 General Purpose Register16 Control Registers16 Floating Point Registers

Most programs only use the General Purpose Registers

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

General Purpose RegistersEach Register is internally designated by 1

hexadecimal digit. ( 0 – F )The Assembler recognizes registers in

context by numeric values. ( 0 – 15 )To help prevent confusion with numeric

values we generally identify registers with R0 – R15.This is done with the assembly Macro EQUREGS

that uses the equate assembler directive.

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

General Purpose RegistersEach register is 4 bytes long, however we

will see later that we can pair registers together to form 8 bytes.

Instructions that use Registers directly, come in 3 basic formats.RR – Register to RegisterRX – Register to Indexed StorageRS – Register to Storage

In this chapter we concentrate on the RX format

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

Review of Data RepresentationWe have already explored Character & Decimal

format.Character format is used for displayable text and

includes A – Z, a – z, 0 – 9 (Standard letters & numerals) '-!"#$%&()*,./:;?@[\]^_`{|}~+<=> (Special

Characters) Control characters

Decimal format is used for arithmetic operations and is stored in the Packed Decimal format Character = Hexadecimal = Packed DecimalC’012345’ X’F0F1F2F3F4F5’ X’012345F’

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

Review of Data RepresentationPacked Decimal format, negative numbers are

represented by the last character byteCharacter = Hexadecimal = Packed DecimalC’01234N’ X’F0F1F2F3F4D5’ X’012345D

Binary format is used primarily for addressing and calculations. Each byte has 8 bits and each bit has an ordinal value.

The above numeric value is 64+4+2 = 70Hex = X’46’, Packed = X’070F’, Character = C’70’

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

128 64 32 16 8 4 2 1

0 1 0 0 0 1 1 0

Review of Data RepresentationBinary format is always a series of ones &

zerosSo to convey a 4 byte value like “BULL” in

binaryConvert each character to it’s binary equivalentCombine in sequence the 4 conversions andSpew forth the answer:

11000010111001001101001111010011There’s got to be a better way, Which is to use

hexadecimal to convey the binary equivalent C2E4D3D3

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

Review of Data RepresentationBinary numbers are a bit strange

Rule 1: If the high-order bit is on the number is negative If the high-order bit is off the number is positive

Rule 2: Negative numbers are stored as 2’s complement of

the positive number Take the positive binary number Complement the bits Add 1

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

Review of Data RepresentationExamples

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

Dec Hex Bin

3 03 00000011

2 02 00000010

1 01 00000001

0 00 00000000

-1 FF 11111111

-2 FE 11111110

-3 FD 11111101

Review of Data RepresentationBinary data will generally be aligned to specific

addresses. All of which are even numbers.D – Doubleword – 8 Bytes long, address is a multiple

of 8F – Fullword – 4 Bytes long, address is a multiple of 4H – Halfword – 2 Bytes long, address is a multiple of

2The Assembler will automatically align to these

addresses by padding with slack bytesWhen defining constants the binary equivalent of

the decimal number will be stored.

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

Register to Indexed StorageThere are 47 RX instructions

All RX instructions are 4 bytes long with the following syntax

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

RX Op Code R1 X2 B20-7 8-11 12-15 16-19 20-31

D2First Halfword Second Halfword

OPERATION OPERANDS

11 #

R X R 1 , D 2 ( X 2 , B 2 )

Register to Indexed StorageThe Load instruction

Loads 4 consecutive bytes into the specified register.

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

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

1 11 #

I 1 L R 1 , O U T

O U T D C F ' 2 1 8 4 5 '

BEFORE AFTERI 1 O U T B'0101010101010101' O U T B'0101010101010101'

R 1 X'????????' R 1 X'00005555'

Register to Indexed StorageThe Store instruction

Stores the specified register into 4 consecutive bytes.

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

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

LABEL OPERATION OPERANDS

1 11 #

I 1 S T R 1 , O U T

O U T D C F ' 0 '

BEFORE AFTERI 1 O U T B'00000000000000000000000000000000'O U T B'01010101010101010101010101010101'

R 1 X'55555555' R 1 X'55555555'

Register to Indexed StorageThe Add instruction

Adds 4 consecutive bytes to the specified register.

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

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

LABEL OPERATION OPERANDS

1 11 #

I 1 A R 1 , O U T

O U T D C F ' 2 1 8 4 5 '

BEFORE AFTERI 1 O U T B'0101010101010101' O U T B'0101010101010101'

R 1 X'00001000' R 1 X'00006555'

Register to Indexed StorageThe Add instruction

When Adding, no Overflow or Underflow will occur.

Condition Code 3 is set if there is a carry out of the high-order bit.

If the program mask has been set to recognize a fixed-point exception. The Fixed-point overflow exception occurs.

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

Register to Indexed StorageThe Subtract Instruction

Subtract behaves the same as the Add instruction except Operand 2 is subtracted from the general purpose register in operand 1.

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

Register to Indexed StorageThe index value in an RX instruction

X2 – is the general purpose register temporarily added to the base register along with the displacement to resolve the Operand 2 address.

Any value from 1 through 15 can be usedBy default X2 is set to zero which is treated as

a NOP.

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

OPERATION OPERANDS

11 #

R X R 1 , D 2 ( X 2 , B 2 )

Convert to BinaryAll data must be in a binary format when

using registers.CVB – Convert To Binary, takes packed

decimal values and stores them in a register in binary format

Op. 2 must be PL8 and on a Doubleword Boundary

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

LABEL OPERATION OPERANDS

1 11 #

I 1 C V B R 1 , P K D A T A

P K D A T A D C P L 8 ' + 2 1 8 4 5 '

BEFORE AFTERI 1 P K D A T A X'21854C' P K D A T A X'21854C'

R 1 X'????????' R 1 X'00005555'

Convert to DecimalCVD – Convert To Decimal, takes a register in

binary format and stores it in packed decimal format.

Op. 2 must be PL8 and on a Doubleword Boundary

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

LABEL OPERATION OPERANDS

1 11 #

I 1 C V D R 1 , P K D A T A

D S 0 D

P K D A T A D C P L 8 ' + 0 '

BEFORE AFTERI 1 P K D A T A X'0C' P K D A T A X'21854C'

R 1 X'00005555' R 1 X'00005555'