Convert Instructions

advertisement

Convert Instructions

syntax

CVTXY source, destination

where X = B, W, L

Y = B, W, L

X

Y

These instructions convert between integer types.

They act like special move instructions, but the source will be converted before the move ex.

Converting from smaller type to longer is done by sign extension. (copying sign bit to all new bits)

Converting from longer type to shorter is done by dropping the leftmost bits (this could result in an overflow situation if the integer can't fit in the new representation)

R5 FFE7 29A0

CVTBW R5, R5 FFE7 FFA0

CVTWL R5, R5 0000 29A0

CVTBL R5, R5 FFFF FFA0

Converting Between Character Code and Two's Complement

CVTSP , CVTPL convert from char code to 2's complement

CVTLP , CVTPS convert from 2's complement to char code

These instructions are needed to convert the input the

READLINE macro reads in into 2's complement, and converts the 2's complements into char code for the PRINTCHRS macro to print.

So far we have assumed that computers work exclusively with binary numbers. Computers allow one or more decimal representations.

The VAX has four ways to store numbers in decimal. we will discuss two of them:

1) Leading Separate

2) Packed Decimal

Leading Separate Numeric

The simplest format for decimal numbers where each digit is stored as a separate byte using the ASCII code, and the sign byte is in the first or leading position.

Each numeric string is identified by

- the address of the first byte (address of the sign byte)

- the length, which is the number of digits not counting the sign from 0 -31

The sign could be +, -, or a blank, but it must be there.

The other characters in the string must be one of the digits from

0 to 9

The digits are stored with the most significant digit following the sign. ex.

if we want to store 1234 in a leading separate format using five digits

VALUE: .ASCII "+1234"

VALUE

2B 31 32 33 34

The leading separate is used in input/output.

Packed-Decimal Format

Used to store decimal numbers in a more compact format.

Digits are packed two to a byte.

Allows length from 0 -31 digits

They are specified by an address and a length.

They are stored with most significant digit first.

The sign nibble is stored after the least significant digit instead of before the most significant as in leading separate.

Digit are stored using the corresponding hex digits. The hex digit C (and A, E, F) is used for + sign, and the D (and B) is used for - sign

If the number of digits in number to be packed is odd, then an even number of nibbles is needed to store the number with its sign. If the number has an even number of digits, then a leading

0 is added to pad the first byte. ex.

01 23 4C

There are instructions, and directives that manipulate packed decimal numbers directly. ex. .PACKED

The convert instructions mentioned above use the packed decimal as an intermediate representation.

Converting from Character Code to Two's Complement

CVTSP s_num, lsn, p_num, packed

This instruction uses R0-R3 for scratch work

 s_num: number of digits (not counting the sign) in the leading separate

 lsn: address for the leading separate string address containing the sign.

 p_num: umber of digits (not bytes) to be put into the packed number.

 packed: address where the packed decimal will be stored.

These instructions are fixed, the number of input digits must be always the same. ex.

if the instruction specifies 3 digit leading separate, then input must be always 3 digit. to input a 1 you must input +001, and so on. ex.

CVTSP #4, VALUE, #5, PACKED

VALUE

2B 31 32 33 34

PACKED

01 23 4C

CVTPL p_num, packed, long

 p_num: number of digits in the packed decimal number

 packed: address of the packed number

 long: longword result. (two's complement)

CVTPL #5, packed, R8

When using CVTSP instruction, the first byte must contain the ASCII code for a +, -, or blank, and each of the other bytes must contain the ASCII code for a digit 0-9.

If the source contains a bad byte then a program exception called reserved-operand fault will occur.

Converting from 2's complement to character code

CVTLP long,p_num, packed

CVTPS p_num, packed, s_num, lsn ex. (on page 104)

R4 contain an integer <= 50,000

LINE: .ASCII /the answer is /

LSN: .BLKB 7

PKD: .BLKB 3

suppose R4 = 0000 01E3

CVTLP R4,#5,PKD

PKD

00 48 3C

CVTPS #5, PKD, #5, LSN

LSN

2B 30 30 34 38 33

PRINTCHRS LINE

will display the following

The answer is +00483

Download