Assignment Document

Signed Numbers, Strings, and Tables

Pages:

Preview:


  • "ORG ; SIX Signed NumbersStrings andTablesOBJECTIVES this chapter enables the student to: • Convert a number to its 2’s complement. • Code signed arithmetic instructions: – ADD, SUB, IMUL, and IDIV. • Demonstrate how arithmetic instructions affect th..

Preview Container:


  • "ORG ; SIX Signed NumbersStrings andTablesOBJECTIVES this chapter enables the student to: • Convert a number to its 2’s complement. • Code signed arithmetic instructions: – ADD, SUB, IMUL, and IDIV. • Demonstrate how arithmetic instructions affect the sign flag. • Explain the difference between a carry and an overflow. • Prevent overflow errors by sign-extending data. • Code signed shift instructions: – SAL and SAR.OBJECTIVES (cont) this chapter enables the student to: • Code logic instruction CMP for signed numbers and explain its effect on the flag register. • Code conditional jump instructions after CMP of signed data. • Explain the function of registers SI and DI in string instructions. • Describe the operation of the direction flag in string instructions. • Code instructions CLD and STD to control the direction flag.OBJECTIVES (cont) this chapter enables the student to: • Describe the operation of the REP prefix • Code string instructions: – MOVSB and MOVSW for data transfer. – STOS, LODS to store and load the contents of AX. – CMPS to compare two strings of data. – SCAS to scan a string for data matching in AX. – XLAT for table processing .6.1: SIGNED NUMBER ARITHMETIC OPERATIONSConcept of signed numbers in computers • Many applications require signed data, & computersmust be able to accommodate such numbers.– The most significant bit (MSB) is set aside for the sign (+ or -) & the rest of the bits are used for the magnitude.– The sign is represented by 0 for positive (+) numbers and 1 for negative (-) numbers. 6.1: SIGNED NUMBER ARITHMETIC OPERATIONSsigned byte operands • In signed byte operands, D7 (MSB) is the sign and D0 to D6 are set aside for the magnitude of the number.– If D7 = 0, the operand is positive. – If D7 = 1, it is negative.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSpositive numbers • The range of positive numbers that can berepresented by the format above is 0 to +127. – If a positive number is larger than +127, a word-sizedoperand must be used. 6.1: SIGNED NUMBER ARITHMETIC OPERATIONSnegative numbers • For negative numbers D7 is 1, but the magnitude isrepresented in 2's complement.To convert to negative number representation (2's complement), follow these steps: 1 1. Write the magnitude of the number in 8-bitbinary (no sign). 2. Invert each bit.3. Add 1 to it.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSnegative numbers The range of byte- sized negativenumbers is -1 to -128. 6.1: SIGNED NUMBER ARITHMETIC OPERATIONSnegative numbers Byte-sized signed number ranges.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSword-sized signed numbers • A word is 16 bits in length in x86 computers. – Setting aside the MSB (D15) for the sign leaves a total of 15 bits (D14 – D0) for the magnitude.• A range of -32768 to +32767.• Larger numbers is must be treated as a multiwordoperand, processed chunk by chunk. – The same way as unsigned numbers.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSword-sized signed numbers The range of signed word operands.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSword-sized signed numbers • To convert a negative number to its word operandrepresentation, the same three steps discussed innegative byte operands are used: 1. Write the magnitude of the number in 8-bit binary (no sign). 2. Invert each bit.3. Add 1 to it.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSsigned number operations overflow problem • When using signed numbers, a serious issue, theoverflow problem, must be dealt with.– The CPU understands only 0s & 1s, ignoring the human convention of positive/negative numbers. • The CPU indicates the problem with the OF (overflow) flag.• If the result of an operation on signed numbers istoo large for the register, an overflow occurs.– Review Example 6-4.6.1: SIGNED NUMBER ARITHMETIC OPERATIONSsigned number operations overflow problem +96 is added to +70 and the result according to the CPU is -90.Why? The result was more than AL could handle, because like all other 8-bit registers, AL could only contain up to +127.The CPU designers created the overflow flag to inform the programmer that the result of the signed number operation is erroneous. "

Related Documents

Start searching more documents, lectures and notes - A complete study guide!
More than 25,19,89,788+ documents are uploaded!

Why US?

Because we aim to spread high-quality education or digital products, thus our services are used worldwide.
Few Reasons to Build Trust with Students.

128+

Countries

24x7

Hours of Working

89.2 %

Customer Retention

9521+

Experts Team

7+

Years of Business

9,67,789 +

Solved Problems

Search Solved Classroom Assignments & Textbook Solutions

A huge collection of quality study resources. More than 18,98,789 solved problems, classroom assignments, textbooks solutions.

Scroll to Top